File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Has anyone sort 2 lists before?

 
Davie Lin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Pie
Posts: 20163
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Davie Lin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul

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.

 
Steve Harney
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Steve.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic