Collection
1. List Interface:
import java.util.List;
import java.util.ArrayList;
public class ListExample {
public static void main(String[] args) {
List<String> names = new ArrayList<>();
// Adding elements to the list
names.add("Alice");
names.add("Bob");
names.add("Charlie");
// Accessing elements by index
System.out.println("First name: " + names.get(0));
// Iterating through the list
System.out.println("Names:");
for (String name : names) {
System.out.println(name);
}
}
}2. Set Interface:
3. Map Interface:
4. Queue Interface:
5. Stack Class:
Last updated