Listnames = new ArrayList<>(); names.add("Alice"); names.add("Bob"); names.add("Charlie"); String name = names.get(1); // Retrieves "Bob" from the list
Listnumbers = Arrays.asList(1, 2, 3, 4, 5); for (int num : numbers) { System.out.println(num); }
ListThe `List` interface is part of the Java Collections Framework, which is a set of interfaces and classes that provide convenient ways to work with collections of data.fruits = new LinkedList<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Cherry"); fruits.remove(1); // Removes "Banana" from the list