Convert List to a Set / Set to List in Java

In Java, When we are working on real time projects.. Generally we came across scenarios like Converting List to Set Object or Vice Versa.

1. Converting a List to a Set Object.
Set<Foo> urSet= new HashSet<Foo>(YourList);
2. Converting a Set to a List Object.
myList.addAll(YourSet);

 

Advertisements

One comment

  1. Hi There,

    Love it absolutely! So crystalline. No mumbo jumbo. No non-sense. Straight and simple. You guys need a standing ovation for your good work.
    I am having a problem with the ‘JTable.print’ feature.
    I am using Java 1.6 on an iMac system with a HP SmartPrint 6510 printer.
    I found a similar problem on your site but the suggestions did not solve my problem. That thread was from 2011.
    The problem is that the format of the printout is fine but the characters are all a nonAscii character in lieu of the expected characters.
    By “the format of the printout is fine” I mean that there is a 5-character heading and there is a line for each item just as I expect. The mystery character is not in the Extended Ascii charts??? It looks like a vertical rectangle that outlines each character???
    The Table is visible in a dialog window that includes the print JButton.
    The selected print button navigates to my ‘doPrint’ method that contains the following code:
    It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
    Keep up the good work!

    Cheers,
    Abhi

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s