1

I want to sort one ArrayList used to display to the user:

String[] listOne = {whip, amulet, cape};

Then sort a second ArrayList used as backed data relative to the first list being sort:

String[] listTwo = {abyssal_whip, amulet_of_power, strength_cape};

Is there any way I can do this?

Jameson
  • 6,400
  • 6
  • 32
  • 53
Syntaxis
  • 69
  • 1
  • 1
  • 8

1 Answers1

0

Don't store two related pieces of data in separate arrays.

Instead create a custom Object that contains both pieces of data. Then you can implement Comparable on your class or write a custom Comparator to do the sorting for you.

For example check out: Sorting using Comparator- Descending order (User defined classes)

for an example that shows you how to:

  1. create a custom Object
  2. create a custom Comparator or implement Comparable.
  3. use the Collections class to do the sorting.
Community
  • 1
  • 1
camickr
  • 321,443
  • 19
  • 166
  • 288
  • thanks camickr that works perfectly, just one thing hope its proberbly somthing dumb, I made the new object but the only way I can create a new List is by creating it in that class then I'm calling the list statically from there how can I create the list from another class? – Syntaxis Mar 08 '15 at 05:25