Thanks to dasblinkenlight's comment I finally understood what you need.
The easiest way to do what you need to do would be to create an object like
class Value implements Comparable<Value> {
int index;
dobule value;
public int compareTo(Value val) {
return Double.compare(this.value, val.value);
}
}
And use it to store the values. Note the Comparable implementation - allows you to use Collections.sort() and Arrays.sort().
You could also not use sorting. Sorting an array is a much more complex operation than finding the minimum value. Just iterate over the array once and find the smallest value and return its index.
double minVal = Double.MAX_VALUE;
int minIndex = -1;
for (int i=0, max=distances.length; i<max;i++) {
if (values[i] < minVal) {
minVal = values[i];
minIndex = i;
}
}
System.out.println("The Nearest to point 1 is point: "+minIndex+" with value "+minVal);
As for indexes: you can't use standard foreach loop if you want to access the index of a given element. One of the reasons is that some collections you may iterate over do not support element ordering (like a Set).
You have to use standard for loop or track the index yourself.
for (int i=0, max=distances.length; i<max;i++) {
System.out.println("["+i+"] "+distances[i]);
}
or
int i = 0;
for (double val : distances) {
System.out.println("["+i+"] "+val);
i++;
}
forloop to have control on the index.