Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - array to linklist

 
Thread Tools Search this Thread
Old 02-08-2004, 09:00 PM   #1
Default array to linklist


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.





jova
  Reply With Quote
Old 02-08-2004, 09:25 PM   #2
Andrew Thompson
 
Posts: n/a
Default Re: array to linklist

jova wrote:
> 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?

> etc...
> }


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/online...ollection.html ,
news:comp.lang.java.help 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


  Reply With Quote
Old 02-08-2004, 09:47 PM   #3
Thomas Schodt
 
Posts: n/a
Default Re: array to linklist

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);
  Reply With Quote
Old 02-08-2004, 10:35 PM   #4
jova
 
Posts: n/a
Default Re: array to linklist

the link class holds the next link in the list.

"Andrew Thompson" <> wrote in message
news:nHyVb.48255$...
> jova wrote:
> > 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?
>
> > etc...
> > }

>
> 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/online...ollection.html ,
> news:comp.lang.java.help 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
>
>



  Reply With Quote
Old 02-09-2004, 12:27 AM   #5
Tony Morris
 
Posts: n/a
Default Re: array to linklist



"jova" <> wrote in message
news:XjyVb.26861$...
> 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)


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump