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 variable
[Java] Array notes
About Java Array List
Java
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 protected
[Java] Annotation
[Java] Module
Studying Java ―― 9
Java tips, tips
Array practice
Java methods
Java method
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
Java learning memo (creating an array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
Studying Java ―― 1
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
FastScanner Java
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Array practice 2