• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1466
  • Last Modified:

ArrayList change object position

Hi all
I want to change the position between 2 objects in an arraylist.
i.e. if my arrayList contains objects as follows:
myObj1
myObj2
myObj3
myObj4
I want to change myObj2 - myObj3:
myObj1
myObj3
myObj2
myObj4

Any ideas?
0
thanassis
Asked:
thanassis
1 Solution
 
effxCommented:
myObjTmp = myObj2
myObj2 = myObj3
myObj3 = myObjTmp
0
 
Ajay-SinghCommented:
Use this,
 
public void swap(List l, int x, int y) {
    Object t = l.get(x);
  l.set(x, l.get(y));
    l.set(y, t);
}
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now