[java] List Collection Framework

[java] List Collection Framework

자바 잼있네요!



 



import java.util.ArrayList; import java.util.List; class coorlist { public int x; public int y; } public class test { public static void main(String[] args) { int i,j; int count = 0; // List< List > wlist = new ArrayList < List >(10); // ------------------------------------------------------- // input // ------------------------------------------------------- for( i=0; i<10; i++) { //List al = (List)wlist.get(i); List list = new ArrayList(); // input 1 coorlist cl = new coorlist(); cl.x = count; cl.y = count++; list.add(cl); // input 2 cl = new coorlist(); cl.x = count; cl.y = count++; list.add(cl); wlist.add( list ); } // ------------------------------------------------------- // output // ------------------------------------------------------- for( i=0; i<10; i++) { List al = (List)wlist.get(i); System.out.println( "=== Num " + i + "번째 ===" ); for( j=0; j<al.size(); j++ ) { coorlist cl = (coorlist)al.get(j); System.out.println( "j = " + j + " : x = " + cl.x + ", y = " + cl.y ); } } } }
// 안없어지네요 ㅜㅜ...에러들이.... 

결과입니다.


=== Num 0번째 ===

j = 0 : x = 0, y = 0

j = 1 : x = 1, y = 1

=== Num 1번째 ===

j = 0 : x = 2, y = 2

j = 1 : x = 3, y = 3

=== Num 2번째 ===

j = 0 : x = 4, y = 4

j = 1 : x = 5, y = 5

=== Num 3번째 ===

j = 0 : x = 6, y = 6

j = 1 : x = 7, y = 7

=== Num 4번째 ===

j = 0 : x = 8, y = 8

j = 1 : x = 9, y = 9

=== Num 5번째 ===

j = 0 : x = 10, y = 10

j = 1 : x = 11, y = 11

=== Num 6번째 ===

j = 0 : x = 12, y = 12

j = 1 : x = 13, y = 13

=== Num 7번째 ===

j = 0 : x = 14, y = 14

j = 1 : x = 15, y = 15

=== Num 8번째 ===

j = 0 : x = 16, y = 16

j = 1 : x = 17, y = 17

=== Num 9번째 ===

j = 0 : x = 18, y = 18

j = 1 : x = 19, y = 19



댓글

Designed by JB FACTORY