How to move specific item in array list to the first item

前端 未结 6 1449
别跟我提以往
别跟我提以往 2020-12-08 13:03

For example : A list

A B C D E

Given C , Switch to

C A B D E

Notice that the array size will change, some items may removed in run times

6条回答
  •  盖世英雄少女心
    2020-12-08 13:34

    Do this:

    1. Remove the element from the list: ArraylistObj.remove(object);
    2. Add the element back to the list at specific position: ArrayListObj.add(position, Object);

    As per your code use this :

    url.remove("C");
    url.add(0,"C");
    

提交回复
热议问题