1.å
³äºArrayList<>
2.JAVA arraylist toString
å ³äºArrayList<>
é¦å æ¥è¯´ä¸ä¸System.out.println(xx);è¿å¥çä½ç¨ã
ä»å®é ä¸æ¯å è°ç¨xx.toString()ã ç¶åè¾åºè¿ä¸ªå¼ã
顺便æä¸ä¸ï¼é»è®¤çtoStringæ¹æ³å°ä¼è¾åº ç±»çåå+â@â+hashç ï¼ä¸æç½ä¹æ²¡å ³ç³»ï¼
åæ¥ç代ç ç»æï¼
ä¸ä¸ªadï¼éé¢åæ¾çå¯¹è±¡æ¯ arrayListã
ä¸ä¸ªmnï¼ éé¢åæ¾ç对象çStringã
å°ä¸¤ä¸ªStringï¼helloï¼worldï¼æ¾å ¥ mnã
å°å·²ç»åæ¾äºä¸¤ä¸ªStringçå«åmnçarrayList æ¾å ¥ad
é£ä¹ï¼ad.getï¼0ï¼ å¾å°çå°±æ¯adè¿ä¸ªarrayListæåæ¾ç第ä¸ä¸ªå¼ï¼èå®é ä¸adéé¢ç¡®å®ä¹åªåäºä¸ä¸ªå¼ï¼å°±æ¯å«åmnçarrayListã
ç»åå¼å¤´è¯´çï¼system.out è¾åºçå°±æ¯mnè¿ä¸ªarrayListçtoStringæ¹æ³ã
arrayListçtoStringæ¹æ³å°±æ¯è¿ä¹ä¸ªæ ¼å¼è¾åº [,游戏脱机源码,,]
å³ï¼å¼å¤´ç»å°¾æ¯ä¸æ¬å·ï¼éé¢æ¯å ç´ çå¼ï¼å ç´ ä¹é´ç¨éå·éå¼ã
以ä¸æ¯çæ¡è¾åºçåå ã
è¥æ³è¦è¾åºmnè¿ä¸ªå符串ï¼è¿ä¸ªé®é¢åèè§å¾æ²¡ææä¸é¢è¯´çé£ä¸æ®µæææäºï¼æ许楼主ä¸æ¯è¿ä¸ªææã
æçç解æ¯ï¼ä½ åªéè¦è¾åº mnè¿ä¸ªå符串ã
æä¾ä¸ç¹æè·¯ï¼
å¨mnéé¢ç¬¬ä¸ä¸ªå æ·»å å符串 mnï¼ä½ ä¸æ¾è¿å»ï¼æä¹è¾çåºæ¥å¢ï¼ï¼
ç¶åå¨system.outéé¢è¾åºmnç第ä¸ä¸ªå¼ä»£ç 为ï¼
ArrayList<String> mn = new ArrayList<String>();
mn.add(âmnâ);
mn.add("hello!");
mn.add("world!");
ad.add(mn);
System.out.println(ad.get(0).get(0));//adçgetï¼0ï¼æ¾çæ¯mnè¿ä¸ªarrayListï¼mnçgetï¼0ï¼ææ¯ âmnâå符串
åªè¦çæ¸ æ¥äºä½ æè¾åºçå°åºæ¯ä»ä¹ä¸è¥¿ï¼å¾èªç¶çå°±è½å¾å°èªå·±æ³å¾å°çä¸è¥¿ã
楼主å¦æä¸æ¯ææåçè¿æ®µä»£ç çæå¾ï¼å¤§å¯ä»¥æ ¹æ®ææä¾çå¾å°èªå·±æ³è¦ç
JAVA arraylist toString
è¦ç¨for循ç¯åï¼
以ä¸æ¯ä¸ä¸ªçå符串ï¼
for(int i=0;i<arrylist.size;i++)
{
System.out.print(arraylist.get(i).toString());
}
å¦æè¦æ³ä¸é´æç©ºæ ¼çè¯å°±è¿æ ·ï¼
for(int i=0;i<arrylist.size;i++)
{
System.out.print(arraylist.get(i).toString()+" ");
}
2024-11-30 00:32
2024-11-29 23:47
2024-11-29 23:40
2024-11-29 23:30
2024-11-29 22:41
2024-11-29 22:33