MainMenu

Home Java Overview Maven Tutorials

Wednesday, 22 April 2020

Difference Between Collection & Collections




Difference between Collection & Collections

Difference between Collection and Collections

1). Collection is a root level Interface in Java Collection Framework or collection hierarchy. The Set, List and Queue are the some of the subInterfaces of Collection interface.

The important methods of Collection interface are add(), remove(), size(), clear() etc.

Collections is a utility class in java.util package which contains only static methods that operate on objects of type collection.

Collections class contains only static methods like sort(), min(), fill(), copy(), reverse() etc.

2). Before Java 8, interface was not allowed to contain static methods. collection is an Interface & interface can contain static methods since java 8 and Interface can also contain abstract methods and default methods.

But collections class contains only static methods.



3). Collection interface extends iterable interface

public interface Collections extends Iterable

and Collections class extends Object class

public class Collections extends Object



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





Example of Collections

import java.io.*;
import java.util.ArrayList;
import java.util.*;

public class ConsTest
{
public static void main(String args[]) throws IOException
{
ArrayList alist = new ArrayList();
alist.add(10);
alist.add(20);
alist.add(5);
alist.add(35);
alist.add(45);
System.out.println("maximum value" + " " + Collections.max(alist));
System.out.println("maximum value" + " " + Collections.min(alist));
ArrayList list = new ArrayList();
list.add("Chandan");
list.add("Chauhan");
list.add("Cha");
Collections.sort(list);
System.out.println("Sorted Strings" + " " + list);
Collections.sort(list, Collections.reverseOrder());
System.out.println("Reversed Strings" + " " + list);
ArrayList slist = new ArrayList(3);
slist.add("Chandan");
slist.add("Chauhan");
slist.add("Cha");
ArrayList dlist = new ArrayList(3);
dlist.add("a");
dlist.add("b");
dlist.add("c");
Collections.copy(dlist, slist);
System.out.println(dlist);
Collections.fill(dlist, "way2testing");
System.out.println(dlist);
}
}

Output :-

maximum value 45
maximum value 5
Sorted Strings [Cha, Chandan, Chauhan]
Reversed Strings [Chauhan, Chandan, Cha]
[Chandan, Chauhan, Cha]
[way2testing, way2testing, way2testing]



31 comments:

  1. Wow, impressive!!! Amazing post, I found a lot of interesting information here. I really appreciate your article. Going to read more new posts.

    Play at a leading online casino in India and grab exciting rewards. ComeOn Casino offers amazing slots, table games, and live dealer casino. Read complete ComeOn Casino review and dive into it.

    ReplyDelete
  2. Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. คาสิโนออนไลน์ได้เงินจริง มือถือ

    ReplyDelete
  3. Have you checked out this naming firm? They now have an online course on creating super sticky brand names. Also, They help you be confident in generating your own names. สล็อตเครดิตฟรีไม่ต้องฝาก

    ReplyDelete
  4. Initial You got a awesome blog .I determination be involved in plus uniform minutes. i view you got truly very functional matters , i determination be always checking your blog blesss. situs slot

    ReplyDelete
  5. OK, so I'm pretty sure you're now thinking how to take advantage of all this good, so here's the flip side of the card. Online casinos are extremely sensitive to bonus abuse, คาสิโนออนไลน์UFABET

    ReplyDelete
  6. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. รีวิวคาสิโนออนไลน์

    ReplyDelete
  7. Many years ago when online casinos started to become popular on the Internet, the owners of the brick and mortar casinos wanted to ban them because they did not want anything cutting into their profits. Since then the question remained the same- which type of gambling is the best kind - playing in a brick and mortar casino or playing in an online casino? There are many questions that one can look at to determine whether or not online casinos are better than the brick and mortar casinos. ufa24h

    ReplyDelete
  8. The casinos on a broader aspect are divided into offline casinos and online casinos. Large resorts, multi starred hotels and luxurious yachts usually feature casino games. These casino games include casino slots, casino tables and various poker rooms. allbet

    ReplyDelete
  9. That having been said, those online casinos have needed to bulldoze the more established types of casino programming that had taken out themselves from the American market. eazycasino

    ReplyDelete
  10. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. สมัคร FIFA55

    ReplyDelete
  11. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. poker

    ReplyDelete
  12. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. situs slot online

    ReplyDelete
  13. Villento Casino is likewise an individual from the Interactive Gaming Council and work under their set of principles ensuring reasonable and legitimate gaming. judi mpo slot

    ReplyDelete
  14. The solitary fruitful path is to have one individual liable for every thing, let them be to play out the errand, however having them report their advancement now and again to the individual doled out in control for the occasion. You will require a lot of time to achieve every one of the undertakings I a fun time span to begin is 4-6 months before the occasion date. sboqq

    ReplyDelete
  15. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. Convert btc to eth

    ReplyDelete
  16. You have beaten yourself this time, and I appreciate you and hopping for some more informative posts in future. Thank you for sharing great information to us. บาคาร่า

    ReplyDelete
  17. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! ufabet

    ReplyDelete
  18. This is actually the kind of information I have been trying to find. Thank you for writing this information. ufabet168

    ReplyDelete
  19. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. บาคาร่า

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. I am definitely enjoying your website. You definitely have some great insight and great stories. slot online

    ReplyDelete
  22. Really a great addition. I have read this marvelous post. Thanks for sharing information about it. I really like that. Thanks so lot for your convene. เว็บคาสิโนออนไลน์

    ReplyDelete
  23. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work morden tower

    ReplyDelete
  24. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. เว็บตรง

    ReplyDelete
  25. Interesting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. morden tower

    ReplyDelete
  26. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. 마이크로게임

    ReplyDelete
  27. If you are looking for more information about flat rate locksmith Las Vegas check that right away. 카지노사이트

    ReplyDelete
  28. Here you will learn what is important, it gives you a link to an interesting web page: Email Extractor Software

    ReplyDelete
  29. I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work. โจ๊กเกอร์123

    ReplyDelete