Advertisement
hemlet

Array_ArrayList

Jan 27th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.ArrayList;  
  2. import java.util.Arrays;  
  3. import java.util.Iterator;  
  4.  
  5.  
  6. public class Array_ArrayList {  
  7.  
  8.     public static void main(String[] args) {  
  9.  
  10.         // String array with data.  
  11.         String[] sArray = new String[] { "Mary", "had", "a", "little", "lamb" };  
  12.         // convert the array to ArrayList  
  13.         ArrayList convArray = new ArrayList<String>(Arrays.asList(sArray));  
  14.  
  15.         // Iterate over the new Array list  
  16.         Iterator iterator = convArray.iterator();  
  17.         while (iterator.hasNext()) {  
  18.             // Print each element to screen  
  19.             System.out.println((String) iterator.next());  
  20.         }  
  21.     }//main
  22. }//Array_ArrayList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement