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.


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

Results 1 to 2 of 2

Thread: Program to populate all array values using the java.util.Arrays class

  1. #1
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Post Program to populate all array values using the java.util.Arrays class

    This code will populate all array values with a given String using the Arrays.fill() command in the java.util.Arrays class.

    In this case, all array values are filled with the String "Java Programming Forums"

    A for-each loop at the end of the code prints the array values to the console.

    import java.util.Arrays;
    public class PopulateArray {
        public static void main(String[] args) {
            // Declare String array called myArray
            String[] myArray = new String[10];
            // Populate all array values
            Arrays.fill(myArray, "Java Programming Forums");
            // for-each loop to print array values
            for (String a : myArray) {
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  2. #2
    Join Date
    Nov 2011
    Thanked 1 Time in 1 Post

    Default Re: How to Populate all array values using the java.util.Arrays class

    Please check the format of the code.

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 04:07 PM.

Similar Threads

  1. How to Sort an Array using the java.util.Arrays class
    By JavaPF in forum Java SE API Tutorials
    Replies: 2
    Last Post: May 17th, 2014, 01:16 AM
  2. Replies: 3
    Last Post: April 26th, 2011, 02:51 AM
  3. Replies: 4
    Last Post: April 29th, 2009, 10:53 AM
  4. Java program to find the minimum and maximum values of input data
    By awake77 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 20th, 2008, 05:12 PM
  5. Details about 'CopyTo' of Arrays in Java
    By Fendaril in forum Collections and Generics
    Replies: 18
    Last Post: November 13th, 2008, 08:31 AM

Tags for this Thread