Java learning memo (creating an array)

Since it is a memorandum memo, details are not described.

Creating an array

・ How to declare an array

It is flexible and can be declared as follows. The number of [] can be used to determine the number of dimensional arrays.

① int[] a;  ② int a[]; ③ int [] [] a; Two-dimensional array ④ int [] a []; Two-dimensional array ⑤ int [] [] a []; 3D array

-Generation of array instance

  1. Specify the number of elements. The following creates an array instance that handles three int type elements and assigns them to the array type variable num. * Reference type It is also possible to use an expression to specify the number of elements if it is an int type.

int[] num = new int[3]; int [] num = new int [2 * 3]; * Calculation formula to return an int type value

  1. Initialization operator You can use the initialization operator {} to instantiate and initialize at the same time. The following is an array type variable str with three String type elements.

String[] str = {“A”,”B”,”C”};

  1. Generate a two-dimensional array later. The number of elements in the first dimension is specified first, and the second dimension is later assigned as an element of the array in the first dimension.

int [][] num = new int[2][];   num[0] = new int[3];   num[1] = new int[2];

It is also possible to specify different numbers of elements as described above.

Recommended Posts

Java learning memo (creating an array)
Java learning memo (method)
[Java ~ Array ~] Study memo 4
Java learning memo (basic)
Java learning memo (interface)
Java learning memo (inheritance)
Java learning memo (data type)
Java learning memo (logical operator)
Java learning memo (abstract class)
Java learning (0)
[Java] array
Java array
java (array)
Java array
[Java] Array
Java memo
Java learning memo (while statement, do-while statement)
[Java] Declare and initialize an array
Java basic learning content 2 (array / ArrayList)
Java array
java array
[Java] Array
(Learning memo) Java Level 2 measures: Question range
Map without using an array in java
Organized memo in the head (Java --Array)
Compare the elements of an array (Java)
java array variable
Java Silver memo
For JAVA learning (2018-03-16-01)
Java learning day 5
java, maven memo
[Java] Array notes
Java SE 7 memo
java anything memo 2
Java specification memo
java learning day 2
Java pattern memo
java learning day 1
[Java] Creating an Excel file using Apache POI
Quick learning Java "Introduction?" Part 1 Building an environment
[Java] Get a random value from an array
Java development environment memo
Java learning 2 (learning calculation method)
java learning (conditional expression)
[java] throw an exception
java basic knowledge memo
Java Kuche Day memo
Java Learning (1)-Hello World
[Java ~ Method ~] Study memo (5)
java se 8 programmer Ⅰ memo
Java paid private memo
Learning memo 01 (forward / redirect)
JAVA learning history interface
About Java Array List
java lambda expression memo
(Memo) Java for statement
Learning memo when learning Java for the first time (personal learning memo)
Java lambda expression [memo]
[Java] Implicit inheritance memo
java competitive programming memo
[Memo] Java Linked List