Switch to full style
Java Collections classes examples .
Post a reply

Iterate on array of strings

Sun Oct 21, 2012 12:54 pm

Iterate on array of strings:
Code:

import java
.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

                String ar1[] = { "car", "pen", "house", "person", "ball" };

                List stringList = new ArrayList();
               
                for 
(String object : ar1) {
                        stringList.add(object);
                }
                Iterator stringsIterator = stringList.iterator();
                
                System
.out.println("Iteration of the strings list");
                while (stringsIterator.hasNext()) {
                        System.out.print(stringsIterator.next() + "\t");
                }
                       
    
}
 
}
 


The output is :
Code:
Iteration of the strings list
car        pen        house        person        ball   




Post a reply
  Related Posts  to : Iterate on array of strings
 Sort strings java-Sorting Array of Strings     -  
 PHP Strings     -  
 C++ Strings     -  
 Trimming Strings in php     -  
 Compare two strings in php     -  
 compare two strings     -  
 compare strings     -  
 Use Switch with strings     -  
 Array difference for associate array     -  
 compare strings with if statement in php     -  

Topic Tags

Java Collections