第2个回答 2013-11-26
//example1:
int[][] array=new int[5][6];
for(int i=0;i<5;i++)
for(int j=0;j<6;j++)
System.out.println(array[i][j]);
...
//example2:
int[][] array={{1,2,3},{5,6},{7,8,9,10,11}};
for(int i=0;i<array.length;i++)
for(int j=0;j<array[i].length;j++)
System.out.println(array[i][j]);
....
这个是二维数组
第3个回答 2013-11-26
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
//集合遍历
public class TestHashSet{
public static void main(String[] args) {
HashSet h = new HashSet();
h.add("1st");
h.add("2nd");
h.add(new Integer(3));
h.add(new Double(4.0));
h.add("2nd"); // 重复元素, 未被加入
h.add(new Integer(3)); // 重复元素,未被加入
h.add(new Date());
System.out.println("开始: size=" + h.size());
Iterator it = h.iterator();
while(it.hasNext()){
Object o = it.next();
System.out.println(o);
}
}
}