File[] roots = File.listRoots();
//方法1:增强型for循环
for(File root : roots){
System.out.println(root);
}
//方法2:常规for循环
for(int i=0;i<roots.length;i++){
System.out.println(roots[i]);
}
//方法3:while循环遍历
int r = roots.length;
int i=0;
while(i<r){
System.out.println(roots[i]);
i++;
}
//方法4:do while() 循环遍历
int r1 = roots.length;
int i1=0;
do{
System.out.println(roots[i1]);
i1++;
}while(i1<r1);
//方法5:数组转换为集合 Iterator遍历
Set<?> set = new HashSet(Arrays.asList(roots));
Iterator<?> it = set.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
//方法1:增强型for循环
for(File root : roots){
System.out.println(root);
}
//方法2:常规for循环
for(int i=0;i<roots.length;i++){
System.out.println(roots[i]);
}
//方法3:while循环遍历
int r = roots.length;
int i=0;
while(i<r){
System.out.println(roots[i]);
i++;
}
//方法4:do while() 循环遍历
int r1 = roots.length;
int i1=0;
do{
System.out.println(roots[i1]);
i1++;
}while(i1<r1);
//方法5:数组转换为集合 Iterator遍历
Set<?> set = new HashSet(Arrays.asList(roots));
Iterator<?> it = set.iterator();
while(it.hasNext()){
System.out.println(it.next());
}