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: Adding to a string array?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding to a string array?

    I have split my string into an array.

    Hello im awesome

    is now:

    helloimawesome

    I now want to add the spaces back into the array

    so helloimawesome would be hello im awesome. I want to add a space only to hello and im. Can you even add new data to existing array elements?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Adding to a string array?

    Once an array is created, its size is set - so no, you cannot directly add new data to an existing array. You could manually create a larger array and copy the previous, or better yet use an ArrayList
    ArrayList (Java Platform SE 6)
    I do not know your intended goal, but you may also want to look into the StringBuilder / StringBuffer classes, which allow dynamic modification of Strings
    StringBuilder (Java Platform SE 6)

Similar Threads

  1. adding varibles to array and using Jlist
    By Fantasy in forum Collections and Generics
    Replies: 1
    Last Post: November 24th, 2011, 06:19 AM
  2. Replies: 3
    Last Post: November 20th, 2011, 02:33 PM
  3. java: adding array elements
    By dambundos in forum Collections and Generics
    Replies: 3
    Last Post: November 4th, 2011, 06:30 AM
  4. [SOLVED] adding to a multidimensional array.
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 27th, 2011, 10:09 AM
  5. adding multiple ints into a string
    By straw in forum Java Theory & Questions
    Replies: 1
    Last Post: March 18th, 2010, 06:02 PM