## Setting value changes different value, why and how to solve?

Hi All,

Can someone help me, please? I have an ArrayList with points. I want to draw a polygon based on this points and create a menu below the most eastern point. For example, assume drawing a flipped L shaped Polygon based on points:

|------------------|
|xxxxxxxxxxxxx|
|xxxxxxxxxxxxx|
|xxxxxxx|-------|
|xxxxxxx|
|xxxxxxx|
|---------|

As you can see, the menu is the most far east x value with the lowest Y value of that 'eastern point'. To do so, I try to calculate what the positions of X and Y are. If X is bigger then before, change the value. If Y is bigger then before while X is the same as before, change the Y. Otherwise the menu will be at the bottom. Only, by calculating if the Y is bigger, I reset the first point of my list. Which is, off course, NOT what I want. Can somebody explain why this happens and how I can fix this, please?

I created a workable demo of the problem. The demo contains four points: just a rectangle is enough to demonstrate the problem. If you run the code below, you will see that after 'MenuLoc Y' is changed, the first point is changed as well.

Java Code:
```import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

public class Poly {

List<Point> polyList;

public Poly() {
// List of points for Polygon
polyList = new ArrayList<Point>();

// Fill list with points

// Point to determine where menu needs to be

for (Point p : polyList) {
System.out.println("Point p is: " + p);
// Determine if position of menu needs to be changed
// Position needs to be as far east with the belonging Y-value

// Determine if x value of point is bigger then current menu position
}
// Determine if y value of point is bigger then current menu position
// But do this only when x value is the same (in case we have a L shaped point)
// THIS IF IS CREATING THE PROBLEM. IF YOU DELETE THIS PART, Point 1 DOES NOT GET CHANGED.
}

// Print values
System.out.println("Point 1: " + polyList.get(0).x + ", " + polyList.get(0).y);
System.out.println("Point 2: " + polyList.get(1).x + ", " + polyList.get(1).y);
System.out.println("Point 3: " + polyList.get(2).x + ", " + polyList.get(2).y);
System.out.println("Point 4: " + polyList.get(3).x + ", " + polyList.get(3).y);
}
}

public static void main(String agrs[]) {
new Poly();
}
}```
Output:
Point p is: java.awt.Point[x=100,y=100]
Point 1: 100, 100
Point 2: 100, 200
Point 3: 200, 200
Point 4: 200, 100
Point p is: java.awt.Point[x=100,y=200]
Point 1: 100, 200 < -- CHANGED!!!
Point 2: 100, 200
Point 3: 200, 200
Point 4: 200, 100
Point p is: java.awt.Point[x=200,y=200]