array to linklist

J

jova

I'm stuck

I have to convert an array to a linklist

the array is initialized as

public Organization{
Crew[] members = new Member [10]

etc....

}
I'm trying to get it setup where Crew holds it's members in a linkedlist


this is what I have so far.
public Organization{
private Link beforeAll = new Link(null,null);

etc...
}

I just can't figure out how to convert it.
 
A

Andrew Thompson

jova said:
I'm stuck ....
I'm trying to get it setup where Crew holds it's members in a
linkedlist .....
this is what I have so far.
public Organization{
private Link beforeAll = new Link(null,null);

What is 'Link' class?

It sounds like you either need the JavaDocs
http://java.sun.com/j2se/1.4.2/docs/api/ , the tutorials
http://java.sun.com/developer/onlineTraining/collections/Collection.html ,
or all three.

One way to do it is to iterate through the
array and add each element to a Vector,
which, implementing Collection, can be
handed to the LinkedList in the constructor.

HTH
 
T

Thomas Schodt

jova said:
I have to convert an array to a linklist

Use Arrays.asList().


Member[] ma = new Member[10];
....
List al = Arrays.asList(ma);
LinkedList ll = new LinkedList(al);
 
J

jova

the link class holds the next link in the list.

Andrew Thompson said:
What is 'Link' class?


It sounds like you either need the JavaDocs
http://java.sun.com/j2se/1.4.2/docs/api/ , the tutorials
http://java.sun.com/developer/onlineTraining/collections/Collection.html ,
or all three.

One way to do it is to iterate through the
array and add each element to a Vector,
which, implementing Collection, can be
handed to the LinkedList in the constructor.

HTH

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
 
T

Tony Morris

jova said:
I'm stuck

I have to convert an array to a linklist

the array is initialized as

public Organization{
Crew[] members = new Member [10]

etc....

}
I'm trying to get it setup where Crew holds it's members in a linkedlist


this is what I have so far.
public Organization{
private Link beforeAll = new Link(null,null);

etc...
}

I just can't figure out how to convert it.

@see java.util.Arrays#asList(Object[])


--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
Joined
Dec 16, 2010
Messages
1
Reaction score
0
Order

Thomas Schodt said:
jova wrote:

> I have to convert an array to a linklist


Use Arrays.asList().


Member[] ma = new Member[10];
....
List al = Arrays.asList(ma);
LinkedList ll = new LinkedList(al);

By doing this, are you guaranteed the List will remain in the same order? As you are converting in to a List before a LinkedList.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top