my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Inserting a new item in arryalist. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inserting a new item in arryalist." Watch "Inserting a new item in arryalist." New topic
Author

Inserting a new item in arryalist.

Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
I have an arryalist of 10 (say) items in it.
I want to push "x" item (not known what it's index might be) to be the second item in the list.
e.g
Arraylist a =[a,b,c,d,e,f,X,h,i,j];
I want to change the items order such that A becomes:
Arraylist a=[a,X,b,c,d,e,f,h,i,j]
Can someone sugest me way to do it?
Thanks!!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
ArrayList::remove( int )
ArrayList::add( int , object )
[ August 15, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118

that should do it.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Can I ask why you want to do that. I ask because maybe ArrayList is not what you really want to use. There isn't enough information in the question to know that.
Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
Thanks Peter and Dirk...
Peter actually it is not pure java application hence i needed this thing to be done in arryalist itself.
Thanks!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting a new item in arryalist.
 
Similar Threads
Removing multiple objects from ArrayList
The Conditional Operator ?:
i need help. [segmented text]
Logic with java code
Recursion help