2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

初心者アレイについて知識

Last updated at Posted at 2022-02-08

#アレイについて文法は

qiita.rb
     int [] array = {};
        int [] array1 = new int [3];//3はこのアレイの長です
        int [] array2 = new int[] {1,2,3};

#間違易いエラーは
arrayindexoutof bounds exception アレイ読み出しの範囲がこのアレイの範囲を超えてる場合発生したエラー例えば

qiita.rb
int[] array = new int[5];
int boom = array[10]; // ここに異常がありです

#アレイコンテンツの表示文法:

qiita.rb
for (int i = 0; i < array.length; i++) {
        	System.out.println(array[i]);	
		}

#array tools:
1.アレイのコンテンツをフォマード表示:

qiita.rb
Arrays.toString();  //[1,2,3]このように表示アレイコンテンツ
        int[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5};

2.アレイの配列:

qiita.rb
Arrays.sort(a);//アレイの配列 「0 1 2 3 4 5 6 7 8 9

3.アレイの配列(順序あり場合)

qiita.rb
String[] intArray = new String[]{"a","b","c","d","e","f","g","h","i","j",};
		int positon = Arrays.binarySearch(intArray, "d");
		System.out.println("position is:"+positon);
  //順序がある条件の上、コンテンツはアレイの位置を探す

4.アレイの配列(順序なし場合)

qiita.rb
for (int i = 0; i < intArray.length; i++) { //無順序の上 コンテンツの位置を探すの場合
			int key = 1;//位置を探したいの数
			if (key == array[i]) {
				System.out.println(i);
			} 

5.アレイのコピー

qiita.rb
int newarray[] = Arrays.copyOf(array, 3);//3はどうこからコピーしたいの位置です

#終わり

2
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?