Basically, if I have an ArrayList<Integer> containing <0, 1, 5, 5, 4, 2>, I need to create a separate ArrayList of <2, 3> for the indexes.
I understand how to get the index for the first appearance of the largest number, but I don't know how to get all of them at the same time.
I was originally thinking:
int highest = 0;
for (int b = 0; b < arrlst.size(); b++) {
int p = arrlst.get(b);
if (highest <= p) {
highest = p;
highestindex.add(b);
}
}
But then I realised that would automatically add the first one, as well as any that were higher than the current max, even if they were not the overall max.
I then thought of putting the highestindex.add(...) part outside the loop but then it would only add the last index and not all of them.