Solved

ArrayList change object position

Posted on 2007-11-25
2
1,419 Views
Last Modified: 2013-11-23
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
Comment
Question by:thanassis
2 Comments
 
LVL 10

Accepted Solution

by:
effx earned 125 total points
ID: 20345800
myObjTmp = myObj2
myObj2 = myObj3
myObj3 = myObjTmp
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 20346913
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now