Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sort Multi Dimension array

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to sort array list with multi dimension value in java using built in function.

Ex:

No Name Address

5 sss US
1 www UK
4 yyyy SL
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a class representing the objects with the given attributes, something like this:



Create/populate the List with these objects:



Create the comparator for these objects:


Invoke the sort utility:
 
Marshal
Posts: 70260
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your post is a little confusing. Do you mean to sort an array or a List? Does the List contain objects of your class? I would say the only object‑oriented way to do it is to create objects of some class or other. Then, as an alternative to the Comparator, you can make that object implement the Comparable interface. You can find more about the interfaces mentioned in the Java Tutorials.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic