|
-
May 1st, 2001, 06:41 PM
#4
Dazed Member
You could if you wanted to use a LinkedList. Which by definition would be: "A collection of ordered objects".
All it is, is a data structure where each element refrences the next element in the list. A doubly linked list is where each element refrences bolth the previous and the next element in the list.
You can use the ListIterator ie.... java.util.ListIterator;
which supports bidirectional iteration of lists. so in effect you can
go back a forth and add and delete elements as you like.
import java.util.*;
class linkedlistExample{
public class void main(String [] args){
LinkedList list = new LinkedList();
list.add("Hello");
list.add("my");
list.add("name");
list.add("is");
list.add("Brandon");
list.display(list);
}
private void display(LinkedList list){
System.out.println("The size of the list is: " + list.size());
ListIterator i = new ListIterator(0);
while(i.hasnext()){
Object o = i.next();
if(o == null){
System.out.println("null");
}
System.out.println(o.toString());
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|