• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Sorting Vectors

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm storing EmployeeInfo Objects into my Vector. EmployeeInfo has attribute Last Name(Primary Sort) and Emp ID (Secondary Sort.)
what is the best way to sort Vector vEmployeeInfo?
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at TreeSet.
 
Alex Iordache
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Treeset ? I can't find anything in MSDN about this. Please be more specific. Thanks.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex--
You can find information about TreeSet here.
Art
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MSDN? Why would a Java developer be looking for anything in MSDN?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HA! I almost said that but refrained!
 
Alex Iordache
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops ! The bartenders are upset.
Sorry with MSDN . It will never happen again.
(Am I having the crazy cow syndrom ?! ;o )
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TreeSet is part "collections", which isn't part of the API in Java 1.1, so it may not be supported by Microsoft. Unless you have a particular reason for using Java 1.1 or Microsoft, you may want to consider using Java 1.2.2 or Java 1.3.
By the way, in case you run across the term, "Java 2 platform" refers to the levels normally referred to as JDK/JRE 1.2 or higher.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your best bet would be to use the Comparator interface.
Here's the link: http://www.java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html
Matt
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use TreeSet you have to use the Comparator interface.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or make EmployeeInfo implement Comparable, so that it has a "natural ordering" and can be sorted without any Comparator. Similar, but not quite the same.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point, Jim. In fact, it might be a bit more efficient to use a Collections.sort since the TreeSet will attempt to maintain order with each add.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!