16.6.2 LinkedList

Figure 16.3 demonstrates various operations on LinkedLists. The program creates two LinkedLists of Strings. The elements of one List are added to the other. Then all the Strings are converted to uppercase, and a range of elements is deleted.

 1   // Fig. 16.3: ListTest.java 2   // Lists, LinkedLists and ListIterators. 3   import java.util.List; 4   import java.util.LinkedList; 5   import java.util.ListIterator; 6  7   public class ListTest 8   { 9      public static void main(String[] args)10      {11         // add colors elements to list112         String[] colors =13            {"black", "yellow", "green", "blue", "violet", "silver"};14         List<String> list1 = new LinkedList<>();15

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.