array to linklist

Discussion in 'Java' started by jova, Feb 8, 2004.

  1. jova

    jova Guest

    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, Feb 8, 2004
    #1
    1. Advertising

  2. 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/onlineTraining/collections/Collection.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
    Andrew Thompson, Feb 8, 2004
    #2
    1. Advertising

  3. 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);
    Thomas Schodt, Feb 8, 2004
    #3
  4. jova

    jova Guest

    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/onlineTraining/collections/Collection.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
    >
    >
    jova, Feb 8, 2004
    #4
  5. jova

    Tony Morris Guest

    "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)
    Tony Morris, Feb 9, 2004
    #5
  6. jova

    Harry Long

    Joined:
    Dec 16, 2010
    Messages:
    1
    Order

    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.
    Harry Long, Dec 16, 2010
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tone
    Replies:
    4
    Views:
    450
    Hywel Jenkins
    Nov 19, 2003
  2. yudi1226

    re:linklist

    yudi1226, Feb 13, 2004, in forum: C Programming
    Replies:
    1
    Views:
    395
    Martin Ambuhl
    Feb 13, 2004
  3. vjay

    Infinite loop problem in linklist

    vjay, Oct 28, 2004, in forum: C Programming
    Replies:
    7
    Views:
    325
    Sastira
    Oct 29, 2004
  4. senthil

    linklist

    senthil, Dec 28, 2004, in forum: C Programming
    Replies:
    8
    Views:
    467
    The Dragon
    Jan 3, 2005
  5. jwvai316

    Nested linklist

    jwvai316, May 16, 2005, in forum: C Programming
    Replies:
    6
    Views:
    394
    BGreene
    Jun 12, 2005
Loading...

Share This Page