Thread: Sorting vectors

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

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    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:
    Code:
    Collections.sort(vectorName.classVariable);
    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
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    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