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 3 of 3

Thread: Dynamic Arrays

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Arrays

    I want to take user input into 2 arrays to store names and marks. One of string type to store names and the other of int type for the marks. I can display them using the index of the element of any particular array.

    However I want the array to be dynamic and it should be filled by the user and not hard coded. What is the best way to go about it. I want to use arrays and not array lists. I dont want to hard code it.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Dynamic Arrays

    Are you sure you want to use arrays? Are you planning to make both arrays the same size and link names to marks by using the same index? That would be a dreadful design - maybe OK if you were programming in Assembler, but a complete waste of Java code.

    You can't resize arrays, but you can copy them to new arrays with a new size with java.util.Arrays - look it up in the Java API documentation.
    java.util.Arrays - Google Search

    edit: just in case you look at the API docs for 1.4 or Java 1.5, 'copyOf' appeared in the Arrays class in Java 6:
    http://download.oracle.com/javase/6/...il/Arrays.html
    Last edited by Sean4u; August 28th, 2011 at 11:18 AM.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Location
    toronto
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Figure out step by step what you want within your program.

    If you want user to do some actions then 'scanner' might be good idea to start.

Similar Threads

  1. Dynamic JComboBoxes ?
    By shad3d in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 16th, 2011, 03:34 PM
  2. Dynamic UI
    By ganeshkumar.salvi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 04:54 AM
  3. Dynamic Web Project + Tomcat 7.0
    By atul.mathur31 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 18th, 2011, 07:01 PM
  4. Dynamic compilation problem
    By hemanth.yerra in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 29th, 2010, 10:51 AM
  5. dynamic method problem...
    By Ranger-Man in forum Object Oriented Programming
    Replies: 8
    Last Post: September 7th, 2009, 04:22 PM