Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    Ok, and how do i do that? haha. and fubarable, this is what happens when you help people who have less developed methods (; Hopefully, when ill be better and eventually be able to use class methods directly, and work around a lot of these minor problems. after all, im only 16, ive got along time...i hope XD

  2. #22
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    Haha Helppppp!

  3. #23
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    By the way, i realize that i could just do this:

    Java Code:
    Comparator<Point> pointorder = new Comparator<Point>(){
               public int compare(Point p1, Point p2) {
                    double sort = p1.getX() - p2.getX();
                    if(sort < 0) {
                        return -1;
                    }else if(sort > 0){
                        return 1;
                    }else{
                     return 0;   
                    }
                }
             };
    But, i am would like to know how to do it the skimed down way, that im having trouble with. ill just sub this in till i figure it out, but i really rally really want to know the other way.

  4. #24
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    That method looks good to me. There isn't a "skimmed down" way except to do the subtraction with the x and y fields.

    Do you know what Fubarable and I mean by those fields?
    Last edited by pbrockway2; 10-27-2010 at 04:38 AM. Reason: Didn't see previous post...

  5. #25
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Also maybe you could post where you are now. I mean how is that comparator being used, and is it giving the sorted order you expect?

  6. #26
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    Well, i will give you the version im on, as soon as im finished with it! im almost there! also, im not sure if i understand what you mean by those fields. and yes, im getting what i want, ive put it through some ordering tests and its working!

  7. #27
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Great. The following isn't intended to sidetrack you - better to stick with something that does what you want.

    The Point class offers methods like getX() and getY() that return coordinates.

    Java Code:
    Point p = new Point(1, 2);
    double foo = p.getX();
    // foo is now the x-coordinate of point p

    But there are also x and y. They aren't methods, so you don't use parentheses. They allow you to directly access the point's data:

    Java Code:
    Point p = new Point(1, 2);
    // p.x is now the x-coordinate of point p

    Consider the expression "p1.x - p2.x". It has the right sign to be returned by compare() and it's of the right type (int).

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Help with java sorting two dimensional array
    By Joycey in forum New To Java
    Replies: 2
    Last Post: 03-27-2010, 03:36 AM
  2. Sorting Array
    By saqib15 in forum New To Java
    Replies: 1
    Last Post: 02-12-2010, 04:42 AM
  3. Sorting an Array via Stacks
    By viperlasson in forum New To Java
    Replies: 0
    Last Post: 02-01-2010, 07:53 AM
  4. Replies: 2
    Last Post: 08-24-2008, 01:30 AM
  5. Sorting an array of Strings
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •