本帖最后由 杨旭 于 2011-12-22 18:29 编辑
- public class Text01{
- public static void main(String[] args) {
- String []str = new String[]{"zxx","lhm","flx"};
- //普通循环
- for (int i = 0; i < str.length; i++) {
- String name = str[i];
- System.out.println(name);
- }
-
- //增强for循环
- for(String name:str){
- System.out.println(name);
- }
-
- }
- }
复制代码- public class Text02{
- public static void main(String[] args) {
- List<String> list = new ArrayList<String>();
- list.add("zxx");
- list.add("lhm");
- list.add("flx");
-
- // 根据集合类长度遍历
- for(int i=0;i<list.size();i++){
- System.out.println(list.get(i));
- }
-
- // 根据迭代器遍历
- for(Iterator i = list.iterator();i.hasNext();){
- System.out.println(i.next());
- }
-
- // 根据增强for循环遍历
- for(String element : list){
- System.out.println(element);
- }
- }
- }
复制代码 |