View Single Post
  #1 (permalink)  
Old 13-03-2010, 01:34 PM
humdinger humdinger is offline
Member
 

Join Date: Nov 2009
Posts: 30
Thanks: 27
Thanked 0 Times in 0 Posts
humdinger is on a distinguished road
Default how to compare two set values

Hi guys,

I need to itterate through 2 sorted sets and compare the values in the set. These sets are of type String and are called listOfNames1 and listOfNames2. If they are not the same i need these values to be added to another set called different.

The code I have is below. This works as I expect it to when i change if (names1 != names2) to if (names1 == names2) but when im trying to get it to add the names that are not the same it just adds all the names in listOfNames1 to the sortedSet different.



Java Code
 public void notTheSame() 
   {
      SortedSet<String>different = new TreeSet<String>();
      for(String names1 : listOfNames1)
      {
         for(String names2 : listOfNames2)
         {
            if (names1 != names2)
            {
               different.add(names1);
            }
         }return null;
      }
Hope someone can help. thankyou in advance for anyone that takes the time to try.

Last edited by humdinger; 13-03-2010 at 02:16 PM.
Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence