Android: ArrayList Move Item to Position 0

后端 未结 4 1261
闹比i
闹比i 2021-01-01 01:49

I have an ArrayList and I need to make sure a specific item is at the 0 position and if it is not, I need to move it there. The item has an isStartIte

4条回答
  •  自闭症患者
    2021-01-01 02:39

    You need to use Collections class's swap method. Collections, with an s at the end.

    Change -

    Collection.swap(myArray, i, 0);
    

    to this -

    Collections.swap(myArray, i, 0);
    

    Take a look at this example.

    Collection and Collections are two different things in Java. The first one is an interface, the second one is a class. The later one has a static swap method, but the former one doesn't.

提交回复
热议问题