I ’m Mari Hosaka.
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.
As an environment ・ Windows 10 ・ Eclipse Pleiades
I don't like it so much yet
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
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.
.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
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