Thread: Sorting vectors

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Rep Power

    Sorting vectors

    Hi guys! I have a vector filled with "user" classes and I want to sort the vector alphabetically by each class's variables, I came across the Collections.sort method and thought it might be useful but I'm not actually sure if it can take a variable from a class thats in a vector as its parameter. I'm not actually in a position to write code right now so I don't have anything to show you guys but I figure if it worked it would go something like this:
    If this or some variation of this idea isn't actually possible do you guys have any other ideas as how I might solve this problem?
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Mobile, Alabama
    Rep Power
    What you could do is write a Comparator for the Vector. Then use the method from Collections that accepts the Vector and Comparator.

IMN logo majestic logo threadwatch logo seochat tools logo