I have pos in the same way, for example in the code

if (controlList.get(pos).getImageUploads().size() > 9) { 

I add no more than 10 items to the list. But there is a snag, I want to always move the first position to the right. Is this possible?

  • 3
    What does “always move the first position to the right”? - post_zeew
  • Well, the value of pos is my first element (picture) by clicking on which I add elements. And I want this position to move to the right. That is, we add a picture and it becomes in place of my pos, and pos in turn moved to the right. - Inkognito
  • I still did not understand anything. Try to reformulate your question. Start by not adding anything in the above code snippet (and say you are adding). - post_zeew
  • just add a new picture / or whatever the index 0 - Andrew Bystrov
  • I advise you to use something that implements the interface Queue - Artem Konovalov

2 answers 2

When working with lists, never forget that element positions start from zero. Those. in order to call the first element of the list, you should call this: Object o = yourList.get(0);

    perhaps, if you understood everything correctly, then like this:

     public void addToFirst(YourType yourItem) { if (yourList.isEmpty()){ yourList.add(yourItem); } else { yourList.add(0, yourItem); } }