File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes problem in converting List to ConcurrentSkipListSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem in converting List to ConcurrentSkipListSet" Watch "problem in converting List to ConcurrentSkipListSet" New topic

problem in converting List to ConcurrentSkipListSet

coder hunter

Joined: Apr 20, 2012
Posts: 1
import java.util.List;
import java.util.concurrent.ConcurrentSkipListSet;

public class ConcurrentSkipListSetEx {

public static void main(String[] args)

List<String> l1 = new ArrayList<String>();

ConcurrentSkipListSet<String> l = new ConcurrentSkipListSet<String>(l1);



this is simple , i am trying to create ConcurrentSkipListSet from List , but when trying to print created ConcurrentSkipListSet , l , it is presenting empty , can any one suggest , if any issue in this
Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

You have two totally separate list objects. You're adding to one, not to the other.

This line: creates a new CSLS object based on the current state of the AL object at the time. After that, you have two totally separate List objects. Adding to or removing from one has no effect on the other. If you put that line after you've added to the AL, you'll see those objects in the CSLS.

(Note also that whatever objects are present in the original list when you copy it to the second one, if you modify the state of any of those objects (as opposed to modifying the state of one of the lists), you'll see that change in both lists. This is because the constructor does a shallow copy. The new list has its own set of references to the objects that the original list had, and changing the references in one list doesn't affect the other. But each reference from one list points to the same object as the corresponding reference in the other list, so changing the state (contents) of that object is visible through both lists' references.)
I agree. Here's the link:
subject: problem in converting List to ConcurrentSkipListSet
It's not a secret anymore!