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: Creating an array with many of the same element?

  1. #1
    Junior Member ShamelessTeenie's Avatar
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Creating an array with many of the same element?

    So I know this is probably a super basic question, but I'm new to Java so please be nice to me

    I'm trying to create a method that creates and returns a String array, with many elements and the same String stored in all of the elements of my array. (Like say, if I wanted to return an array of 600 elements that stored of the String "hello world" in each one). I'd post the code that I have so far, but I really don't have anything substantial; all I've been able to do is create the method.

    I'm sorry to bother everyone with such a simple question, but I've searched online and looked through my textbook, and haven't been able to find anything. Thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Creating an array with many of the same element?

    There are no restrictions on how many elements in an array have the same value.
    array[4] = aStr;
    array[55] = aStr;
    array[234] = aStr;
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member ShamelessTeenie's Avatar
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Creating an array with many of the same element?

    Oh! Now that I see it, it seems so obvious. Thank you so much!

Similar Threads

  1. How can I remove a element from an array?
    By seaofFire in forum Java Theory & Questions
    Replies: 3
    Last Post: April 23rd, 2012, 03:42 PM
  2. add new element in array
    By allen_k in forum Collections and Generics
    Replies: 3
    Last Post: December 11th, 2011, 03:13 PM
  3. Replies: 2
    Last Post: October 18th, 2011, 07:11 PM
  4. Taking an element out of an array
    By SlckP in forum Collections and Generics
    Replies: 3
    Last Post: May 5th, 2010, 02:26 PM
  5. how to find an element in an array
    By humdinger in forum Collections and Generics
    Replies: 8
    Last Post: April 9th, 2010, 05:22 PM