for(String item:strArray)
System.out.println(item)
这句是遍历strArray,,,那item 是干嘛的。

解决方案 »

  1.   

    你可以把 item 换成  aaa,bbb或者ccc 试试.就是遍历strArray出来的元素呗,为了方便你操作
      

  2.   

    item  是一个变量名
    声明要符合规则 且 还需要有一定的意义
    它的作用是接收strArray每个元素的引用
      

  3.   

    item是strArray数组遍历过程中具体每个元素的引用。类似:for(int i=0;i<strArray.length();i++){
    String item=strArray[i]
    }你的那个item类似于上面传统for循环里的item变量,指向每次遍历过程中拿到的String。楼主的foreach循环是JDK5.0新增的语法,和传统的for功能一样,只是书写起来更方便。这种语法好像是借鉴C#的。
      

  4.   

    Java中一种增强的for循环,遍历的时候
    比起传统的for(int i =0;i< array.leng();i++)
    语法更加清晰
      

  5.   

    item 是集合中的存放的某一下标的元素。
      

  6.   

    4L说的对。那个item只是个临时的变量,用于存放strArray的每一个String元素。此增强型循环,从jdk1.5版本开始有的。
      

  7.   

    item是定义的一个变量,你也可以定义成别的  比如 abc ddd等等  这是增强的for循环 遍历的时候用起来挺方便的 而且看起来也整洁
      

  8.   

    For-each LoopPurpose
    The basic for loop was extended in Java 5 to make iteration over arrays and other collections more convenient. This newer for statement is called the enhanced for or for-each (because it is called this in other programming languages). I've also heard it called the for-in loop.Use it in preference to the standard for loop if applicable (see last section below) because it's much more readable.Series of values. The for-each loop is used to access each successive value in a collection of values.Arrays and Collections. It's commonly used to iterate over an array or a Collections class (eg, ArrayList).Iterable<E>. It can also iterate over anything that implements the Iterable<E> interface (must define iterator() method). Many of the Collections classes (eg, ArrayList) implement Iterable<E>, which makes the for-each loop very useful. You can also implement Iterable<E> for your own data structures.General Form
    The for-each and equivalent for statements have these forms. The two basic equivalent forms are given, depending one whether it is an array or an Iterable that is being traversed. In both cases an extra variable is required, an index for the array and an iterator for the collection.For-each loop Equivalent for loop
    for (type var : arr) {
        body-of-loop
    }
    for (int i = 0; i < arr.length; i++) { 
        type var = arr[i];
        body-of-loop
    }
    for (type var : coll) {
        body-of-loop
    }
    for (Iterator<type> iter = coll.iterator(); iter.hasNext(); ) {
        type var = iter.next();
        body-of-loop
    }
    Example - Adding all elements of an array
    Here is a loop written as both a for-each loop and a basic for loop.double[] ar = {1.2, 3.0, 0.8};
    int sum = 0;
    for (double d : ar) {  // d gets successively each value in ar.
        sum += d;
    }
    And here is the same loop using the basic for. It requires an extra iteration variable.double[] ar = {1.2, 3.0, 0.8};
    int sum = 0;
    for (int i = 0; i < ar.length; i++) {  // i indexes each element successively.
        sum += ar[i];
    }
    Where the for-each is appropriate
    Altho the enhanced for loop can make code much clearer, it can't be used in some common situations.Only access. Elements can not be assigned to, eg, not to increment each element in a collection.
    Only single structure. It's not possible to traverse two structures at once, eg, to compare two arrays.
    Only single element. Use only for single element access, eg, not to compare successive elements.
    Only forward. It's possible to iterate only forward by single steps.
    At least Java 5. Don't use it if you need compatibility with versions before Java 5.
    Copyleft 2006 Fred Swartz MIT License
      

  9.   

    item是一个变量,for循环梅执行一次,就将数组中的元素赋值给item,如:item=strArray[0]...item=strArray[n]
      

  10.   

    item是一个变量,用来放置你遍历strArray得到的每一个元素的