Conceptsarraylist Collectionssortingenhanced For Loopcollections



ArrayList – Collections


Enhanced For Loop



Add 5 names to the collection. Bob Susan … Output the Strings onto the console using the enhanced for loop.

2. Sort the list using the method Collections.sort. Output the sorted List. Shuffle the list, and output the shuffled list. Note that Collections (with an s) is a class, while Collection is an interface. The Collections class has many useful static methods for processing interfaces, including the sort method.

3. Search for the name Susan in the list. What location was it found? Search for a name that is not in the list. What location is reported?

4. Convert the list above to an array using toArray. Output the elements of the array. Convert the array back into a list using asList. Output the elements of the list.

Java Programming