How to initialize Java array

Since there are various declaration & initialization methods, I have identified the ones that do not cause a compile error.

python


public class A {

	public static void main(String[] args) {
		/*One-dimensional array*/
		int[] ary = new int[3];
		int ary2[] = new int[3];
		int []ary3 = new int[3];
		
		int ary4[];
		ary4 = new int[3];
		
//		int ary4[];
//		ary4 = {1, 2, 3};  #=>Compile error
		
		int ary5[] = {1, 2, 3};
		int ary6[] = new int[] {1, 2, 3};  //Specify type and initialize
//		int ary7[] = new int[3] {1, 2, 3};  #=>Compile error
		
		/*Two-dimensional array*/
		int[][] ary8 = new int[3][3];
		int ary9[][] = new int[3][3];
		int []ary10[] = new int[3][3];
		int[] ary11[] = new int[3][3];
		int [][]ary12 = new int[3][3];
		
		int ary13[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
	}
}

Recommended Posts

How to initialize Java array
How to make a Java array
[Java] How to use Map
How to lower java version
[Java] How to use Map
How to uninstall Java 8 (Mac)
Java --How to make JTable
How to use java Optional
How to minimize Java images
How to write java comments
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
How to use Java Map
How to set Java constants
How to use Java variables
How to convert Java radix
[Java] How to implement multithreading
[Java] How to use Optional ①
[Java] array
Java array
Java array
java (array)
Java array
[Java] Array
Java array
How to convert a file to a byte array in Java
java array
[Java] Array
How to study Java Silver SE 8
How to use Java HttpClient (Get)
Studying Java # 6 (How to write blocks)
[Java] How to update Java on Windows
How to make a Java container
How to use Java HttpClient (Post)
[Java] How to use join method
How to learn JAVA in 7 days
[Processing × Java] How to use variables
How to decompile java class files
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to write Java variable declaration
[Java] How to use List [ArrayList]
How to use classes in Java?
How to name variables in Java
How to pass Oracle Java Silver
How to turn Iterator Dojo (Java)
java Eclipse How to debug javaScript
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] Convert array to ArrayList * Caution
[Java] How to use Math class
How to find Java prime numbers
How to use Java enum type
How to concatenate strings in java
For Java beginners: List, Map, Iterator / Array ... How to convert?
How to check Java installed on Mac
How to make a Java calendar Summary
How to implement date calculation in Java