I have 2 list of custom objects. Both are queries from same table in DB. The bigger list is with a specified column NOT NULL and the smaller list is with the specified column NULL. Pretty much all of the properties in the custom object are String. I need to have a way to compare one of the properties and merge the 2 list into one. Is that possible?
It's quite likely possible, although you would have to clean up the description of what you want to do. Right now it's a bit incomplete, or maybe garbled. I don't see what "compare one of the properties" is supposed to mean, and your post title mentions sorting but your post itself doesn't.
But anyway, yeah, it's probably doable.
Joined: Aug 05, 2007
The "Compare one of the properties" should be more like String.compareTo(OtherString) > 0 or < 0 or ==0 and sort them accordingly and place it into a new list. Merge these two into one and return it. I have try using iterator and the new list had duplicates. I will try a different approach` with List API.
Joined: Jun 19, 2010
I think the TreeSet will give you what you are after, Implement a Comparator to define the order you are after and make sure that your classes implement both the .equals() and .hashcode() methods.
It will remove duplicates and once you are done you can convert it out to an array.
The other option if the values are already in a database table, are you able to form a db query to give you what you are after?