Java Welcome to the Swamp of 2D Arrays

Nice to meet you

I ’m Mari Hosaka.

This is the first post

I think that there are various poor parts, but thank you. Also, because it's a paper that is just starting out in Java The level is quite low, please forgive me.

Immediately ...

As an environment ・ Windows 10 ・ Eclipse Pleiades

Do you like arrays?

I don't like it so much yet

Background why I got hooked

Loop processing by specifying the number of times in the For statement Write this code. Well, then if the array itself can be managed with variables in the first place Doesn't it look good? Call by index number Isn't it possible to reduce the amount of result description?

I shouldn't have thought that, the swamp door opens

Sorry to keep you waiting

Now, let's introduce the swamp, this time we will insert the array into the array. Can you imagine it? I can't. This time, from the viewpoint of simplification and readability Use a static array [].

But all arrays can be multidimensional ArrayList of dynamic array and It can also be described in the associative array HashMap.

Swamp sample code

.java



//1. 1. First, we will generate an array

String[] a = { "1", "yosiko", "kanagawa", "woman", "26" };
String[] b = { "2", "kenji", "kobe", "man", "23" };
String[] c = { "3", "vanri", "osaka", "man", "19" };

.java


//Then declare a variable that can store the new array

String[][] Lists = {a ,b ,c };

//...Hmm? Hmm?

I understand that comfortably

<Is it true?

・ I can't get an image in the first place ・ I don't feel the benefits

Often the analogy of variables You use cardboard boxes and oranges, right?

<That's right!

If you put it in a box, you can easily take out the oranges.

But there is something other than oranges in the box If you have a lot of fruit in it It's hard to understand, right?

,, ha!

Then put each fruit in a box If you put them all together in a big box It's easy to figure out what's in it!

Sample.java


//Put two oranges in the cardboard box 1
//Put two apples in the cardboard box 2
String[] cardboardBox1 = {"mikan1", "mikan2"};
String[] cardboardBox2 = {"ringo1", "ringo2"};

/*
So, a big cardboard box to put together the cardboard boxes
I'll prepare and put it together
*/

String[][] bigCardboardBox = {cardboardBox1, cardboardBox2};

//At the time of variable declaration[]Note the number of

System.out.println(bigCardboardBox[0][0]);
// ="mikan1"Is displayed
System.out.println(bigCardboardBox[1][1]);
// ="ringo2"Is displayed

When you want to eat one closed mandarin orange, the first thing to open is Big ➀ cardboard box 。 Looking at the contents opened after that, this time Another ➁ cardboard box There is.

I finally saw a mandarin orange. (... .println(bigCardboardBox[X][Y]);) (Specify the arguments of the variables [row] and [column] of the two-dimensional array)

Each operation of this flow Running in programming If you can grab it I'm happy.

I thought it would be easier to understand if there was an illustration I will also post a link!

[Java] What is a two-dimensional array? http://ysklog.net/java/5-18.html

Finally

I feel like I've done it, but when I look back There is no connection or change of origin It feels poor, but I wrote it I feel like I was able to organize my mind I'm glad I did it.

Recommended Posts

Java Welcome to the Swamp of 2D Arrays
Welcome to the Java Library Swamp! !!
Output of the book "Introduction to Java"
Java, about 2D arrays
[Java] How to get the authority of the folder
[Java] How to get the URL of the transition source
How to write Scala from the perspective of Java
[Java] How to get the maximum value of HashMap
Java: Use Stream to sort the contents of the collection
Input to the Java console
Get to the abbreviations from 5 examples of iterating Java lists
20190803_Java & k8s on Azure The story of going to the festival
Command to check the number and status of Java threads
[Java] To know the type information of type parameters at runtime
How to derive the last day of the month in Java
The story of pushing Java to Heroku using the BitBucket pipeline
Be sure to compare the result of Java compareTo with 0
[Java] Delete the elements of List
[java8] To understand the Stream API
'% 02d' What is the percentage of% 2?
[Java version] The story of serialization
[Java] Input to stdin of Process
Java, arrays to start with beginners
[Processing × Java] How to use arrays
The origin of Java lambda expressions
[Swift5] How to get an array and the complement of arrays
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
From fledgling Java (3 years) to Node.js (4 years). And the impression of returning to Java
I tried to summarize the methods of Java String and StringBuilder
How to check for the contents of a java fixed-length string
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
Dynamically increase the number of elements in a Java 2D array (multidimensional array)
Get the result of POST in Java
[Java] How to use the File class
Check the contents of the Java certificate store
Java reference to understand in the figure
Examine the memory usage of Java elements
Introduction to java for the first time # 2
The story of forgetting to close a file in Java and failing
[Java] How to use the hasNext function
[Java] Get the day of the specific day of the week
[Java Servlet] The road of Senri is also one step to the first
[java] Summary of how to handle char
Java SE8 Silver ~ The Road to Pass ~
[Java] How to use the HashMap class
Memo: [Java] Check the contents of the directory
About the procedure for java to work
[Java] How to use the toString () method
Studying how to use the constructor (java)
Compare the elements of an array (Java)
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
[day: 5] I summarized the basics of Java
What are the updated features of java 13
Easily measure the size of Java Objects
How to find out the Java version of a compiled class file
[Java] [Maven3] Summary of how to use Maven3
Looking back on the basics of Java
[Java] How to get to the front of a specific string using the String class
How to find the total number of pages when paging in Java