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]



65 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
  30. This was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself.. 카지노api

    ReplyDelete
  31. While i fully grasp this article. I am certain Men and women in shape a lot of try and create this specific article. While i benefit from your career. dewapoker

    ReplyDelete
  32. This is valuable data! We've acquired absolutely appreciated looking at versions facts and now have visit the finish you are suited regarding several. You are very good. dewapoker

    ReplyDelete
  33. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. sa gaming

    ReplyDelete
  34. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. สล็อตไม่มีขั้นต่ำ

    ReplyDelete
  35. Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. สล็อตแตกง่าย

    ReplyDelete
  36. I should assert barely that its astounding! The blog is informational also always fabricate amazing entitys. promotion code

    ReplyDelete
  37. As a matter of fact, it's not exactly as awful as it looks. Luckily, I was betting utilizing a couple of spread-betting organizations' demo destinations.sbobet

    ReplyDelete
  38. This blog is so nice to me. I will keep on coming here again and again. Visit my link as well.. online casino bonus

    ReplyDelete
  39. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. asia999

    ReplyDelete
  40. Since online casino games are very straightforward,http://202.95.10.77/ the vast majority believe that they can't assist them with bringing in cash on the web.

    ReplyDelete
  41. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. เว็บไทเกอร์

    ReplyDelete
  42. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. Dice Betting

    ReplyDelete
  43. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. เซ็กซี่บาคาร่า

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

    ReplyDelete
  45. This was really an interesting topic and I kinda agree with what you have mentioned here! visto turistico per il Canada

    ReplyDelete
  46. various guides are accessible that can help the player. These guides incorporate outlines and adding machines that can help players in gaining the essential measurable data.judi poker qq online

    ReplyDelete
  47. You completed a few fine points there. I did a search on the subject and found nearly all persons will go along with with your blog. MS Office download free

    ReplyDelete
  48. This is such a great resource that you are providing and you give it away for free. tanzania betting sites

    ReplyDelete
  49. find the best Bet Domains For Sale on SportsBettingDomain.com, premium bet gambling domains for sale. Bet Domains For Sale

    ReplyDelete
  50. Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. เว็บพนันออนไลน์

    ReplyDelete
  51. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. Bandar Bola

    ReplyDelete
  52. I think this is a really good article. You make this information interesting and engaging. You give readers a lot to think about and I appreciate that kind of writing. Game Online

    ReplyDelete
  53. Thanks so much for sharing this awesome info! I am looking forward to see more postsby you! 토토사이트

    ReplyDelete
  54. Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. madhur day

    ReplyDelete
  55. I think this is an informative post and it is very beneficial and knowledgeable. Therefore, I would like to thank you for the endeavors that you have made in writing this article. All the content is absolutely well-researched. Thanks... สมัครเว็บบอล

    ReplyDelete
  56. Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. สล็อต

    ReplyDelete
  57. The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. joker927

    ReplyDelete
  58. What a thrilling post. It is extremely chock-full of useful information. Thanks for such a great info. joker898

    ReplyDelete
  59. Your blog has piqued a lot of real interest. I can see why since you have done such a good job of making it interesting. I appreciate your efforts very much. sa gaming

    ReplyDelete
  60. Attractive, post. I just stumbled upon your weblog and wanted to say that I have liked browsing your blog posts. After all, I will surely subscribe to your feed, and I hope you will write again soon! สล็อตโจ๊กเกอร์

    ReplyDelete
  61. It is especially decent, though look into the tips during this home address. 토토사이트

    ReplyDelete
  62. Outstanding article! I want people to know just how good this information is in your article. Your views are much like my own concerning this subject. I will visit daily your blog because I know. It may be very beneficial for me mobiledsng.com

    ReplyDelete