• Post Reply Bookmark Topic Watch Topic
  • New Topic

sort arrays  RSS feed

 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone i was trying to find some information about sorting arrays. i haven't found anything that can help me out so far. i want to be able to sort arrays by all different types in the same array.
for example in the array i will store a property address, property value, area of land, owners name. i want to be able to sort the array by any field. i will have a button to sort the array by address. another button to sort by value, and so on. the only thing i have found was i need to add something to property class but that way looks like it can only accept that field to sort and i want to be able to sort by anything. thank you for the help. i can post my code if need be but it is very large and i think its not really necessary. thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew,
The Arrays.sort() method allows you to provide your own comparator. You could write a Comparator<Object> which will let you compare different types. It seems odds to do this, but I can't think of a reason it wouldn't work.

You still have to define the sort logic of course.
 
matthew reid
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply ill look into that more and try it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!