private LinkedList <Point>theSnake; theSnake = new LinkedList<Point>();
Now I want to add 3 points to the link list and I've done this by creating a temporary variable and using setLocation to change the location of the point the adding it to the Link List as such:
Point temp = new Point(); temp.setLocation(center,center+1); theSnake.add(temp); theBoard[center][center+1] = snake; temp.setLocation(center,center); theSnake.add(temp); theBoard[center][center] = snake; temp.setLocation(center,center-1); theSnake.add(temp);
theBoard is just an integer array and snake is just a static variable for a number and center is just some value. Anyways. When I print out the Linked List right after this snippet of code, the Link List is completely filled with the last value of temp. Just literally (center,center-1) three times. Which means that "temp" is being added to the linked list by reference. I'm so confused. I thought java never did this and everything was done by value. Eitherway is there a way to only add the value of temp to the linked list instead of its reference?