Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Use variable in array declaration statement

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Use variable in array declaration statement

    Quick question. I have to create a byte array for lines of text. There might be 1 line, or 23 lines, there’s no way of knowing, but every line needs its own array. What I would like to do is create each array as needed. byteArray (x) and instantiate a new array for each new line as they arrive. So byteArray1 if there was one line, byte arrays: byteArray1, byteArray2, byteArray3 if there were three lines, etc. Does that make sense? Is it possible to do that? If so, how?

    Thanks for your help.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,372
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: Use variable in array declaration statement

    Use a two dim array. The first dim having an element for each line, the second dim would have the byte array for that line.
    If you know the max number of lines, then there is no problem.

Similar Threads

  1. Overriding methods declaration problems
    By TurboTuring in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 9th, 2010, 11:23 AM
  2. Very beginner - What's wrong in my applet declaration?
    By rforte in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 30th, 2010, 04:54 AM
  3. FAQ: find variable in an array of objects
    By dalek in forum Object Oriented Programming
    Replies: 1
    Last Post: April 5th, 2010, 12:40 PM
  4. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 06:57 PM
  5. Assigning variable to an Array
    By sridevi in forum Collections and Generics
    Replies: 3
    Last Post: August 10th, 2009, 10:58 PM