String sArray[] = new String []{"Array 1", "Array 2", "Array 3"};
//convert array to list
List lList = Arrays.asList(sArray);
//iterator loop
Iterator<String> iterator = lList.iterator();
while ( iterator.hasNext() ){
System.out.println( iterator.next() );
}
//for loop
for (int i=0; i< lList.size(); i++)
{
System.out.println( lList.get(i) );
}
//while loop
int j=0;
while (j< lList.size())
{
System.out.println( lList.get(j) );
j++;
}
Source:
http://www.mkyong.com/java/how-do-loop-iterate-a-list-in-java/
No comments:
Post a Comment