Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class myClass {
- public static void main(String[] args){
- // Convert stuff array to a list
- String[] stuff = {"apples", "beef", "corn", "ham"};
- List<String> list1 = Arrays.asList(stuff);
- System.out.println("List = " + list1);
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!
- // Converting an array into a 'List' means stable size
- // For varied size, we need 'ArrayList'
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!
- ArrayList<String> list2 = new ArrayList<String>();
- list2.add("Youtube");
- list2.add("Google");
- list2.add("Digg");
- System.out.println("ArrayList = " + list2);
- Collections.addAll(list2, stuff);
- System.out.println("ArrayList with 'addAll' = " + list2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement