Java Interview Questions: Understanding Collection vs Collections

Collection is an interface while Collections is a java class1 min


what is collection in java

The difference between Collection and Collections is an important interview question for Java freshers.
This question has been used to test the knowledge of Java Collections Framework. Make sure you go through this question before appearing for the interview.

This question is quite confusing as both Collection and Collections are looking similar by name. But they are completely different. Collection is an interface while Collections is a utility class. In this post, I will be sharing the difference between Collection and Collections in Java along with examples.

Don't miss: JDK 21: Latest Features and Improvements You Need to Know in Java

Difference between Collection and Collections

Collection vs collections difference java beingcoders

Major Differences :- extends

1) Extends: Collection interface extends iterable interface.

public interface Collections 
extends Iterable

On the other hand, Collections class extends Object class.

public class Collections
extends Object

2) Static methods : Collection is an interface. Interface can contain static methods since java 8. Before java8, interface was not allowed to contain static methods. Interface can also contain abstract methods and default methods.
On the other hand, Collections class contains only static methods.

Image from Edureka | Collections tree


3) Type: Collection is a root-level interface in Java Collection Framework or collection hierarchy.
Collections is a utility class in java that contains only static methods that operate on or return collections.

Important Points:

1. Most of the java collections framework classes inherit from Collection interface.

2. Set, Queue and List are some of the main subinterfaces of Collection interface.

3. Map interface is also part of the Collections Framework. But it doesn't inherit Collection interface.

4. The jdk does not provide direct implementation of Collection interface. Although, it provides implementation of specific subinterfaces like Set, List and Queue.

5. HashSet, ArrayList, LinkedHashSet, Vector, PriorityQueue are some indirect implementations of Collection Interface.

6. Collections is a utility class in java which contains only static methods. Using this class methods you can search for a particular element in a collection. It also contains the methods to sort the collection.

Similarities between Collection and Collections in Java

1. Both are part of the Java Collections Framework.

2. Both are present in java.util package.

3. Both are added to jdk in java version 1.2

Winding Up

Please mention in the comments in case you have any doubts regarding the difference between Collection and Collections in java.

adsense


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
1
Cute
Love Love
1
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
1
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Legend

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

0 Comments

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment