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[] things = {"apples", "noobs", "pwnge", "bacon", "goATS"};
- List<String> list1 = new LinkedList<String>();
- for(String x : things){
- list1.add(x);
- }
- System.out.println(list1);
- String[] things2 = {"sausage", "bacon", "goats", "hattypotter"};
- List<String> list2 = new LinkedList<String>();
- for(String y : things2){
- list2.add(y);
- }
- System.out.println(list2);
- // BUILT-IN METHODS
- // addAll, previous, next, subList, clear
- list1.addAll(list2);
- list2 = null; // Free space
- printMe(list1);
- removeStuff(list1, 2, 5);
- printMe(list1);
- reverseMe(list1);
- } // END OF MAIN
- private static void reverseMe(List<String> list1) {
- ListIterator<String> it = list1.listIterator(list1.size());
- while(it.hasPrevious()){
- System.out.printf("%s ", it.previous());
- }
- }
- private static void removeStuff(List<String> list1, int from, int to) {
- list1.subList(from, to).clear();
- }
- private static void printMe(List<String> list1) {
- for(String b : list1){
- System.out.printf("%s ", b);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement