1. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
haha! thank you, you understood the question, it was much more simple then i was making it. heres the new code!

Java Code:
```package medianmedianline;
import java.util.*;
import java.awt.*;;
public class Main {
public static void main(String[] args) {
Point p = new Point();
int count = 0;
int x = 0;
int y = 0;
ArrayList <Point> point = new ArrayList();

while(count <= 10){
x = count;
y = count;
count++;
}

System.out.println("Points: " + point);
}
}```
the output is "Points: [java.awt.Point[x=0,y=0], java.awt.Point[x=1,y=1], java.awt.Point[x=2,y=2]...." Haha thank you guys (: im sure.... actually i know ill be back here for help!

2. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
8
Java Code:
```ArrayList<Point> myPoints=new ArrayList<Point>();
Point p;
for(int i=0;i<someValue;i++){
// get two points and store in variables x and y
p=new Point(x,y);
System.out.println("["+myPoints.get(i).getX()+", "+myPoints.get(i).getY()+"]");
}```

3. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
Marshy, isnt that kind of doing the same thing? haha, this may be related to your snippet of code or not, but, is there a way to pull all of the x variables from the arraylist, and sort the arrylist by X acceding order, so like, arralyist: [[1,2],[3,2],[2,2]], after sorting it would look like [[1,2],[2,2],[3,2]]. haha, this is easy with other variables but the Collections.sort(point); method, doesn't work. or at least it doesn't the way i have it written.

4. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
8
haha yeah I posted without realising you got it. Hmm maybe extending Point and implementing Comparable

5. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
Haha ok, i will need help with a few things. i may be able to do it, if i could return the x's of the points in the arraylist to int's. Being able to do that would also help me with a lot of other things.

6. Senior Member
Join Date
Feb 2010
Location
Waterford, Ireland
Posts
748
Rep Power
8
why dont you use the ArrayList's get() method to get a Point and then use .getX()

Java Code:
```ArrayList<Point> myPoints=new ArrayList<Point>(Arrays.asList(new Point(2,2),new Point(3,3)));

int x=(int)myPoints.get(0).getX();```

7. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
Ah geez haha, i keep forgetting ordering operations today, yes, then i can accomplish that task for getting x without needing to give the point a reference name.

8. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15
You may want a collection of x-coords for some other reason, but you don't need them for sorting the points.

Use the version of sort() that takes a Comparator argument.

Implementing Comparable makes sense if there is a natural ordering in your particular case. But it may equally be the case that you want to sort based on different criteria: x-coord, y-coord, distance from the origin, angle from the horizon etc. You would have to do a bit of study on Comparators but, once mastered, they are very flexible.

9. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
Yea, my research has told me this, I notices that there is natural order, and another type of ordering. is natural order, order only based on like variables? Allso, i need equal elements to be sorted in my case.

10. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15
"Natural order" doesn't really have a meaning! It's ordering ... that is natural.

Show sizes have a natural ordering: from little to big. But shoes themselves can be ordered in all sorts of ways: price, style, age of intended foot etc. In Java code these may or may not be associated with instance variables (that's an implementation detail, whereas being comparable in a certain way is a property of the type of thing regardless of how it is implemented.) And some instance variables may represent things that have no natural ordering.

As I suggested in my other post Point is more like Shoe than it is like Weight. There doesn't seem to me to be any one way of comparing Point instances that is more natural than all others. (And my example was chosen to illustrate the fact that a trivial change in coordinate system might result in quite different ordering requirements.)

11. Senior Member
Join Date
Sep 2010
Posts
109
Rep Power
0
Ok, i understand. Now how do organize my list? ive used the sort meathod alot, but its the comparable sort thats the problem, please explain how i would use it in my code example on my other post?

Page 2 of 2 First 12

#### Posting Permissions

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