# [SOLVED] JAVA storing coordinates in an array??



## huggies12345

Hi,

I have some coordinates that need to be put into an array.

Here is what i did, it is wrong but it shows what i want to do:

Point[] objectPoints = new Point [6];

objectPoints[0] = {474, 232};
objectPoints[1] = {129, 235};
objectPoints[2] = {452, 150};
objectPoints[3] = {266, 503};
objectPoints[4] = {526, 654};
objectPoints[5] = {135, 340};


On the first list 474 would be the x coordiante and 232 would be the y coordinate. etc.

How do i store them properly??

Thanks.


----------



## Special2God

*Re: JAVA storing coordinates in an array??*

just change to: 
objectPoints[0] = *new Point(474, 232);* 
...
...

Because your array is a 'Point[]' array, we have to put Point objects inside and Java does not understand that you want two integers {474, 232} to represent a point. 
So you have to tell it that you want the two integers to be a Point and then put the Point into the array. 

As a rule of thumb, an array of some class, whether it be Point, String, int, etc. can only hold objects that match it's array type. 
A String will never fit into a Point array, an int will never fit into a String array, and a Point will never fit into an int array, etc.


----------



## huggies12345

*Re: JAVA storing coordinates in an array??*

Thanks.

So would it be:

Point[] objectPoints = new Point [6];

objectPoints[0] = new point{474, 232};
objectPoints[1] = new point{129, 235};
objectPoints[2] = new point{452, 150};
objectPoints[3] = new point{266, 503};
objectPoints[4] = new point{526, 654};
objectPoints[5] = new point{135, 340};


----------



## Special2God

*Re: JAVA storing coordinates in an array??*

Almost, replace the {} with (), and all Java classes are capitalized so point is Point. 

Point[] objectPoints = new Point [6];

objectPoints[0] = new Point(474, 232);
objectPoints[1] = new Point(129, 235);
objectPoints[2] = new Point(452, 150);
objectPoints[3] = new Point(266, 503);
objectPoints[4] = new Point(526, 654);
objectPoints[5] = new Point(135, 340);


----------



## huggies12345

*Re: JAVA storing coordinates in an array??*

OK.

Thanks for the help.


----------



## Special2God

Glad I could help!


----------

