Java Program that Shows Use of Collection Interface Last Updated : 22 Jul, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The Collection framework is a unified architecture for representing and manipulating collections, enabling collections to be manipulated independently of implementation details. Uses and advantages of Collection Framework: This reduces the efforts of programmers by providing data structures and algorithms, so we do not have to write them.This increases performance by providing a high-performance implementation of data structures and algorithms.This provides interoperability between unrelated APIs by establishing a common language to pass collections back and forth.Reduces the effort required to learn APIs by requiring you to learn multiple ad hoc collection APIs.This provides static methods that perform useful functions on collections, such as sorting a list.This provides Wrapper implementation which adds functionality, such as synchronization, to other implementations. And many more advantages it provides for us to use and tackle the problems of development. Usages: Examples of different types of Interfaces are given below: List InterfaceLinked ListMap Interface Stacks Use Case 1: List Interface Java // Java Program that Shows Use of Collection Interface // ArrayList import java.util.*; class GFG { public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("Geeks"); list.add("areyou"); list.add("working"); list.add("hard?"); Iterator itr = list.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } } } OutputGeeks areyou working hard? Use Case 2: Linked List Java // Java Program that Shows Use of Collection Interface // LinkedList import java.util.*; // Class testing java Collection public class GFG { // Main driver method public static void main(String args[]) { // Creating a LinkedList LinkedList<String> al = new LinkedList<String>(); // Adding elements to above linked list al.add("Geeks"); al.add("areyou"); al.add("working"); al.add("hard?"); // Iterator Iterator<String> itr = al.iterator(); // Condition check over elements inside using // hasNext() method which holds true till there is // element inside list while (itr.hasNext()) { // Printing elements of LinkedList System.out.println(itr.next()); } } } OutputGeeks areyou working hard? Use Case 3: Map Interface Java // Java Program that Shows Use of Collection Interface // Hash-Map import java.util.*; public class GFG { // Main driver method public static void main(String[] args) { // Creating a Map Map<Integer, String> map = new HashMap<>(); // Adding elements to map map.put(1, "Geeks"); map.put(2, "are"); map.put(3, "you"); map.put(4, "working"); // Traversing Map // Converting to Set so that traversal is accessed Set set = map.entrySet(); // Iterator Iterator itr = set.iterator(); // Condition check over elements inside using // hasNext() method which holds true till there is // element inside list while (itr.hasNext()) { // Converting to Map.Entry so that we can get // key and value separately Map.Entry entry = (Map.Entry)itr.next(); // Printing elements inside HashMap System.out.println(entry.getKey() + " " + entry.getValue()); } } } Output1 Geeks 2 are 3 you 4 working Use Case 4: Stacks Java // Java Program that Shows Use of Collection Interface // Stack import java.util.*; public class GFG { // Main driver method public static void main(String args[]) { // Creating a stack in memory Stack<String> stack = new Stack<String>(); // Adding elements to stack stack.push("Geeks"); stack.push("are"); stack.push("you"); stack.push("working"); stack.push("hard?"); // pop() returns all elements of stack stack.pop(); //. iterator Iterator<String> itr = stack.iterator(); // Condition check over elements inside using // hasNext() method which holds true till there is // element inside list while (itr.hasNext()) { // Print all popped elements System.out.println(itr.next()); } } } OutputGeeks are you working Comment More infoAdvertise with us Next Article Output of Java Programs | Set 34 (Collections) GeeksforGeeks Improve Article Tags : Java Java-Collections Practice Tags : JavaJava-Collections Similar Reads Output of Java Programs | Set 33 (Collections) Prerequisite: Java - Collections 1. What is the output of following Java Program? Java import java.util.ArrayList; class Demo { public void show() { ArrayList<Integer> list = new ArrayList<Integer>(); list.add(4); list.add(7); list.add(1); for (int number : list) { System.out.print(numbe 3 min read Output of Java Programs | Set 34 (Collections) 1. What is the Output of the following Java Program? Javaimport java.util.LinkedList; class Demo { public void show() { LinkedList<Integer> list = new LinkedList<Integer>(); list.add(1); list.add(4); list.add(7); list.add(5); for (int i = 0; i < list.size(); i++) { System.out.print(li 3 min read Collection Interface in Java The Collection interface in Java is a core member of the Java Collections Framework located in the java.util package. It is one of the root interfaces of the Java Collection Hierarchy. The Collection interface is not directly implemented by any class. Instead, it is implemented indirectly through it 6 min read Iterator vs Collection in Java Iterator and Collection, both has helped and comforted the programmers at many a times. But their usage and application has a very wide difference. 1. Iterator Declaration public interface Iterator Type Parameters: E - the type of elements returned by this iteratorIterators are used in Collection fr 3 min read Evolution of Interface in Java In Java, interfaces define a contract for classes without specifying how the methods are implemented. With time, Java has introduced major enhancements or we can say evolution of interfaces to make them more powerful. So, in this article, we will explore the evolution of interfaces in Java from Java 3 min read Match Lambdas to Interfaces in Java One of the most popular and important topics is lambda expression in java but before going straight into our discussion, let us have insight into some important things. Starting off with the interfaces in java as interfaces are the reference types that are similar to classes but containing only abst 5 min read Like