获取数组里面的内容并输出显示。
使用循环输出数组
public class Welcome {public static void main(String[] args){String[] runoobs = new String[3];runoobs[0] = "百度";runoobs[1] = "谷歌";runoobs[2] = "火狐";for (int i = 0; i < runoobs.length; i++){System.out.println(runoobs[i]);}}
}
结果输出
百度
谷歌
火狐
使用for语句输出
import java.lang.*;
public class Main{ public static void main(String args[]) { String[] runoobs = new String[3]; runoobs[0] = "百度"; runoobs[1] = "谷歌"; runoobs[2] = "火狐"; for (String obj:runoobs){ System.out.println(obj+"\n"); } }
}
使用迭代遍历打印元素
import java.util.*;
import java.lang.*;
public class Main { public static void main(String args[]) { ArrayList<String> runoobs = new ArrayList<String>(); runoobs.add("www."); runoobs.add("baidu"); runoobs.add(".com"); for (Iterator<String> iterator = runoobs.iterator(); iterator.hasNext(); System.out.println(iterator.next())) { } }
}