[Java] Array notes

Array

--Array type --Array --Multidimensional array --Array for syntax --Extended for syntax --Sample program for averaging int array elements

Array type

Array

I want to use it because the abbreviation is easy, but considering garbage, I also want to remember the formal way of writing using new. Even though there is a ** garbage collection **, if there is a new where it is omitted, be aware of it and write the abbreviation.

//Formal writing
int[] scores; //Declaration of array variables
scores = new int[3]; //Declaration of array elements
scores[0]=10; //Array element assignment
scores[1]=20;
scores[2]=30;

//Abbreviation
int[] scores = new int[]{10,20,30};
int[] scores = {10,20,30};

//All equivalent

Multidimensional array

//Formal writing
String[][] scores = new String[2][3];
scores[0][0]="A1";
scores[0][1]="A2";
scores[0][2]="A3";
scores[1][0]="B1";
scores[1][1]="B2";
scores[1][2]="B3";

//Multidimensional array abbreviation
String[][] scores = {{"A1","A2","A3"},{"B1","B2","B3"}};

//All equivalent

Array for syntax and extended for syntax

Array name.length: Now get the number of array elements and use

//Creating an array
int[] scores = {10,20,30};

//General for syntax
for (int i=0; i<scores.length; i++){
	System.out.println(scores[i]);
}

//Extended for syntax
for (int value:scores){
	System.out.println(values);
}

For multidimensional arrays


//Creating an array
int scores[][]={{10,11,12},{21,22,23}};

//General for syntax
for(int i=0; i<scores.length; i++){
	for(int ii=0; ii<scores[i].length; ii++){
		System.out.println(scores[i][ii]);
	}
}

Reference book

[Introduction to Java 2nd Edition] (https://www.amazon.co.jp/dp/B00MIM1KFC/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1) Pp.138-166

Recommended Posts

[Java] Array notes
[Java] array
Java array
Java array
java (array)
Java array
[Java] Array
java notes
Java array
java array
[Java] Array
java array variable
Java Generics (Notes)
[Java] Study notes
Java serialization notes
[Java] Stream Collectors notes
Java formatted output [Notes]
[Java] Control syntax notes
Java NIO 2 review notes
About Java Array List
[Java ~ Array ~] Study memo 4
[Java] Basic method notes
[Java] List type / Array type conversion
Array
Try scraping using java [Notes]
[Implementation] Java Process class notes
Java Collections Framework Review Notes
Java
Java Development Basics ~ Exercise (Array) ~
[Java] Convert ArrayList to array
Java
[Java Silver] Array generation method
How to initialize Java array
[Beginner] Java basic "array" description
Array
Java learning memo (creating an array)
[Java] Basic types and instruction notes
[Java] Output multidimensional array / spreadsheet (AOJ⑥ spreadsheet)
[Java] Declare and initialize an array
Java array variables are reference types
Java basic learning content 2 (array / ArrayList)
Notes on signal control in Java
[Java] Difference between array and ArrayList
Notes on Android (java) thread processing
Notes on Java path and Package
[Java] Conversion from array to List
How to make a Java array
Java array / list / stream mutual conversion list
[Java] Convert array to ArrayList * Caution
Java learning (0)
Java protected
When seeking multiple in a Java array
[Java] Module
[Ruby] Array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Array practice
Java methods
Java method
[Java] Multidimensional array / inner product calculation (AOJ⑦ inner product)