Results 1 to 7 of 7
- 01-10-2011, 10:29 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Ordered list - inserting wherever on the list
Hi,
I'm looking for and ordred list structure. The problem is that the lists I found I only could insert object at the begining or at the and of the list. I want to be able to insert objets at any place of the list because I want it to be ordered.
does anybody knows how can I do it?
Thanks in advance
- 01-10-2011, 10:39 AM #2
Have you checked ArrayList ?
Specifically, ArrayList.add(int index, Object element)
This inserts the specified element at the specified index position in this list.
Does that satisfy your need?
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-10-2011, 10:52 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Thanks Goldest,
I that's what I was looking for.
Mnem
- 01-10-2011, 10:56 AM #4
You are Welcome! :D
Java Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-10-2011, 11:58 AM #5
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Thanks Goldest,
One more question about it.
If we have a list with two objects and we want to insert an object between them. The existing two objects have the indexes 1 and 2 for exemple. We want the new object to be the one with the index 2 and the actual with the index 2 to have the index 3. If we execute: arraylist.add(2, new object), will it place the actual with index 2 to the third positiion or it will put the new object in place of the existing deleting the actual in the 2 position?.
I would like it to insert the new object between the two existing, otherwise I would have to move the objects to free the second position and then insert the new object.
Mnem
- 01-10-2011, 12:06 PM #6
This is what javadoc has to say about this:
"Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices)."
Which means, if you insert a new object between index 1 and 2, the new object will sit at index 2 and old object at index 2 will move to index 3.
Hope that's clear,
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 01-10-2011, 12:21 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
How do I list values of an arrays in a comma seperted list
By nmvictor in forum New To JavaReplies: 2Last Post: 11-22-2009, 05:24 PM -
How do I list values of an arrays in a comma seperted list
By nmvictor in forum New To JavaReplies: 3Last Post: 11-21-2009, 05:48 PM -
Now stuck with inserting data into a list.
By mainy in forum New To JavaReplies: 2Last Post: 07-31-2009, 03:49 PM -
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks