Results 1 to 5 of 5

Thread: Arrays

  1. #1
    Sharoo is offline Member
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    28
    Rep Power
    0

    Default Arrays

    Hi everyone,
    I was wondering if someone could give me a hand with my problem.
    So I have set up an array that has 20 positions available in it (0 - 19) and I have initialised values in the first five positions (0 - 4). Now my issue is that when I use a scanner to input data into a field it replaces the data I already have there. I think I would need to use a while or if statement and search for a "null" position and then place the new data there, but I'm not 100% sure.
    Any help would be greatly appreciated.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default Re: Arrays

    You could do that, but using a List of some form (ArrayList or LinkedList) would be easier.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Sharoo is offline Member
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    28
    Rep Power
    0

    Default Re: Arrays

    Could you please enlighten me on this List method, I don't think I have ever used one before I'm still only a Java beginner.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default Re: Arrays

    Quote Originally Posted by Sharoo View Post
    Could you please enlighten me on this List method, I don't think I have ever used one before I'm still only a Java beginner.
    An ArrayList (or LinkedList) is like an array but it grows when you add a new element to it so you don't have to keep track of it; read its API documentation for the gory details.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Sharoo is offline Member
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    28
    Rep Power
    0

    Default Re: Arrays

    Thank you so much :)
    It sounds like a list is the way to go.

Similar Threads

  1. arrays and multidimensional arrays
    By belfast09 in forum New To Java
    Replies: 5
    Last Post: 06-14-2011, 02:28 PM
  2. Arrays
    By sarah jain in forum New To Java
    Replies: 7
    Last Post: 03-01-2011, 12:41 AM
  3. store array of arrays in array of arrays
    By joost_m in forum New To Java
    Replies: 4
    Last Post: 04-19-2010, 11:32 AM
  4. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 02:40 AM
  5. Arrays
    By TheRocket in forum New To Java
    Replies: 6
    Last Post: 12-10-2008, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •