Suppose I have an ArrayList of objects of size n. Now I want to insert an another object at specific position, let\'s say at index position k (is greater than 0 and less tha
For example:
I want to move the element from 23th to 1th(index == 0) in the arrayList, so I put 23th element to a temp value, and removing from list, insert it to 1th in list. It's worked, but not more efficient.
List list = JSON.parseArray(channelJsonStr,ItemBean.class);
for (int index = 0; index < list.size(); index++) {
if (list.get(index).getId() == 23) { // id 23
ItemBean bean = list.get(index);
list.remove(index);
list.add(0, bean);
}
}