java frame set iterator

Is a collection of elements taken iterator manner.

Remove the manner defined inside the set, this embodiment can be removed to access the content directly to elements of the collection, then taken out was defined manner become inner classes, and the different data structures for each container, so that the details are not the same action taken, However, there are commonalities and content determination removed. These similarities can be drawn. These internal classes meet a rule that the Iterator is, the extracted object acquisition method: iterator ();

public  static  void main (String [] args) { 
        the ArrayList AL1 = new new the ArrayList (); 
        al1.add ( "java01" ); 
        al1.add ( "java02" ); 
        al1.add ( "java03" ); 
        al1.add ( "java04" ); 
        the iterator IT = al1.iterator (); // Get an iterator for the collection of elements taken 
        the while (it.hasNext ()) { 
            System.out.println (it.next ()); 
        } 
    }

 public static void main(String[] args) {
        ArrayList al1 = new ArrayList();
        al1.add("java01");
        al1.add("java02");
        al1.add("java03");
        al1.add("java04");
        for (Iterator it = al1.iterator();it.hasNext();){
            System.out.println(it.next());
        }
    }

Local variables is released, more preferably.

 

Guess you like

Origin www.cnblogs.com/hongxiao2020/p/12634839.html