Answer the question
In order to leave comments, you need to log in
How to raise an element in a collection?
Question: There is a collection of class objects, you can get values through getters.
How can I raise a specific element of the collection to the very top? For example, we have this:
456 adminX
935 test
864 user
We need to elevate the test user so that it turns out like this:
935 test
456 adminX
864 user
Answer the question
In order to leave comments, you need to log in
For ArrayList:
int i = 0;
for (; i < players.size(); i++) {
if (players.get(i).getId() == 935)
break;
}
players.set(0, players.set(i, players.get(0)));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question