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) {
- String[] stuff = {"babies", "watermelon", "melons", "fudge"};
- // Convert a string array into a linked list with this constructor
- // Reason: I CAN USE LIST'S METHODS INSTEAD OF ARRAY'S
- LinkedList<String> thelist = new LinkedList<String>(Arrays.asList(stuff));
- System.out.println(thelist);
- thelist.add("pumpkin");
- thelist.addFirst("first");
- System.out.println(thelist);
- // Convert back to an array
- stuff = thelist.toArray(new String[thelist.size()]);
- for(String x : stuff){
- System.out.printf("%s ", x);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement