Collection Frameworks in Java
Collection Frameworks in Java
Collection Frameworks in Java
Collection: The root interface of the JCF, which provides a way to work with
collections of objects.
List: A type of collection that allows elements to be stored in a specific order.
Set: A type of collection that does not allow duplicate elements.
Map: A type of collection that stores key-value pairs.
Queue: A type of collection that allows elements to be added and removed in a
specific order.
Here is a list of some of the key classes in the Java Collections Framework:
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
System.out.println(list);
}
}
This code creates an ArrayList object and adds two elements to it. It then prints
the contents of the list to the console.
Methods of Collection interface
There are many methods declared in the Collection interface. They are as follows: