Syntax

Java Create an Array Syntax

In Java, create an array: creates a fixed-size array — int[] nums = {1, 2, 3}; int[] empty = new int[5];

Quick Answer

Syntax
int[] nums = {1, 2, 3}; int[] empty = new int[5];
JavaSyntax

Create an Array

Code example
int[] nums = {1, 2, 3}; int[] empty = new int[5];

Creates a fixed-size array.

Learn More

How to create an array in Java

  1. Open your Java file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Java Create an Array Syntax

Use int[] nums = {1, 2, 3}; int[] empty = new int[5];.

Related Syntax References

Frequently asked questions

What is the Java syntax for create an array?

Use this pattern: int[] nums = {1, 2, 3}; int[] empty = new int[5];

Can I copy this Java code example?

Yes. Use Copy code and adapt the example to your program.

Is this Java syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify