Java array

Introduction

Even if it is said that you can make it by progressive, repeating, and conditional branching, you can't make it at all! !! (Not related to this post)

Array

** Variables can only contain one value **, but ** arrays can contain multiple values ** together. One column is called ** one-dimensional array **, and two or more columns are called ** multidimensional array **. Each one is called ** element **, and the number is called ** element number **.

kane.java


Data type[]Array variable name;
Array variable name=new data type[Element count];

String[] banana;
banana = new string[3];

banana[0] = "Cavendish"
banana[1] = "Lakatan"
banana[2] = "GrosMichel"

The above describes the declaration and assignment separately Below is the declaration and assignment at the same time

kane.java


Data type[]Array variable name= {Element 1,Element 2,...};

String[] banana = {"Cavendish", "Lakatan", "GrosMichel"}

Write [] after the data type (like ** int [], String [] **)

** Element overwrite is array variable name [index number] = "new element" **

Each element can be obtained ** by the array name [index number] **.

kane.java


String[] banana = {"Cavendish", "Lakatan", "GrosMichel"};

banana[1] = "LadyFinger" //Overwriting elements

System.out.println(banana[1]);

//Execution result Lady Finger

Multidimensional array

Excel spreadsheet software

banana 0 1
0 Cavendish Lakatan
1 GrosMichel LadyFinger

kane.java


Data type[][]Array variable name;
Array variable name=new data type[Element count][Element count];

String[][] banana;
banana = new string[2][2];

banana[0][0] = "Cavendish"
banana[0][1] = "Lakatan"
banana[1][0] = "GrosMichel"
banana[1][1] = "LadyFinger"

System.out.println(banana[1][0]);

//Execution result GrosMichel

This can also be omitted

kane.java


String[][] banana = {{"Cavendish", "Lakatan"},{"GrosMichel","LadyFinger"}};

System.out.println(banana[0][0]);

//Execution result Cavendish

At the end

I understand that multidimensional arrays are convenient, but I get a flat tire because my head is one-dimensional.

Recommended Posts

[Java] array
Java array
Java array
java (array)
[Java] Array
Java array
java array
[Java] Array
[Java] Array notes
Array
About Java Array List
Java
[Java ~ Array ~] Study memo 4
Java
Array
[Java] List type / Array type conversion
Java Development Basics ~ Exercise (Array) ~
[Java] Convert ArrayList to array
[Java Silver] Array generation method
How to initialize Java array
[Beginner] Java basic "array" description
Java learning (0)
Studying Java ―― 3
[Java] Annotation
[Java] Module
[Ruby] Array
Java tips, tips
Array practice
Java methods
Java method
java (constructor)
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java learning memo (creating an array)
Java static
Java serialization
JAVA paid
Java (set)
java shellsort
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Studying Java ―― 1
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Array practice 2
[Java] Output multidimensional array / spreadsheet (AOJ⑥ spreadsheet)