Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1474
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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