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: How to add to an array with user input

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to add to an array with user input

    I would like to add to an array from input thru a textfield when the add button is pushed.
    array im adding to:
       String[] name = {"Stapler", "Pens", "Paper", "Staples"};
    I have a gettext methode already declared. The problem is i dont know the code to apply it into the array.

    psudocode

    add button
    textfield.gettext
    apply textfield.gettext to name{}


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to add to an array with user input

    You can not change the size of an array by adding to it. You can change the contents of an array by assigning values to any of the slots in the array:
    theArray[theIndex] = aValueForTheArray; // assign a value to a slot in an array
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. User Input help
    By lanmonster in forum What's Wrong With My Code?
    Replies: 20
    Last Post: January 20th, 2013, 10:44 AM
  2. Take user input
    By frabbi.cse in forum Java Theory & Questions
    Replies: 1
    Last Post: July 22nd, 2012, 12:48 PM
  3. Placing user input to a array and to then display it as a string
    By LaliB in forum Collections and Generics
    Replies: 5
    Last Post: January 12th, 2012, 11:41 AM
  4. Append data from user input into array
    By brncao in forum Collections and Generics
    Replies: 1
    Last Post: October 11th, 2011, 04:37 AM
  5. Valid user input
    By ChristopherLowe in forum Java Programming Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM