Method calculating percentages (from array which I don't want to be changed but it is):
private float values[] = { AGREE, DISAGREE };
private float[] calculateData(float[] data) {
// TODO Auto-generated method stub
float total = 0;
for (int i = 0; i < data.length; i++) {
total += data[i];
}
// 180 is the amount of degrees of the circle - setting it up to half
// circle 360 means full circle
for (int i = 0; i < data.length; i++) {
data[i] = 180 * (data[i] / total);
}
Calling the method:
float[] degrees = calculateData(values);
If I log the values of array before this method was called I get 1.0,1.0 but after method was called I get 90.0,90.0 why? If I don't change values[]
.
I know that it is happening here in that method because when I remove it I get 1.0,1.0 (what I actually want to get)
EDIT:
Thank you for the answers so if I understand it correctly: if parameter of the method is changed also the object set to be parameter, when method was called, becomes changed.