Shorthand way to create an array and initialize it with constant values: - Java Language Basics

Java examples for Language Basics:Array

Description

Shorthand way to create an array and initialize it with constant values:

Demo Code

public class Main {

  public static void main(String[] args) {
    String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday" };

    int[] primes = { 2, 3, 5, 7, 11, 13, 17 };

    primes = new int[] { 2, 3, 5, 7, 11, 13, 17 };
  }//w  ww  . java 2 s  . c  o m

}

Related Tutorials