• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sort an arraylist that it is a different type based on array that also a different type

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey

My Question is how can i sort an Arraylist that it is a Different Type (Not string or nothing like that, i mean like custom item) based on array that different type (custom type)

I have no code but if there is some one that have any suggestions how to do it feel free to post here.

Thanks in advance
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what do you mean by "...based on array that different type"?

You can write what's called a comparator. this basically takes two objects, and determines if one is greater than, equal to, or less than the other, based on whatever criteria you define. If I had "house" objects, I could write my comparator to decide based on price of the house, on their ages, on their number of bedrooms...or whatever I want.

I then pass this to the sort methods that already exist, and it does the rest.

I'm sure if you search this forum, you will find some other threads on this very topic.
 
Amit Shef
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to sort ArrayList that based on the sort of Array
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Shef wrote:I want to sort ArrayList that based on the sort of Array



How did you sort the array in the first place? Did you use the java.util.Arrays class? And using either Comparable or a Comparator?

If so, you can sort the List, using the java.util.Collections class, using the same, either Comparable or Comparator.

Henry
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Shef wrote:I want to sort ArrayList that based on the sort of Array


i'm not trying to be a pain, but that isn't really a spec. you're really just repeating what you already said in your first post.

Specs are supposed to be SPECIFIC. how do you sort one array (or ArrayList) based on the sort of another array? a specific example would help, but remember that is only part of a spec, not the complete spec.
 
reply
    Bookmark Topic Watch Topic
  • New Topic