0
1

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 5 years have passed since last update.

自分用Java基礎知識

Last updated at Posted at 2018-12-30

ドキュメント

制御構造

以下の構文の定義は厳密にはこちら

if (真偽値を表す式) ブロック/文
if (真偽値を表す式) ブロック/文 else ブロック/文
switch (値を表す式) { //char, byte, short, int, Character, Byte, Short, Integer, String, or an enum type
    case 固定の値: ブロック/文
    default: ブロック/文
}
for (ローカル変数初期化式リスト; 真偽値を表す式; 式) ブロック/式
for (ローカル変数宣言 : iterableな値を表す式) ブロック/式
while (真偽値を表す式) ブロック/文
do ブロック/文 while (真偽値を表す式);

switch/for/while/doのブロック/式を抜けるにはbreak;とする。
ラベル付きブロック/式を指定して抜けるにはbreak ラベル;とする。

サンプル
Sample.java
public class Sample {
	public static void main(String[] args){
		for (int i=0; i<5; i++) {
			hoge: {
				fuga: {
					if (i==1) {
						break fuga;
					} else if (i==2) {
						break hoge;
					} else if (i==3) {
						break;  //ここでforのブロックを抜けるのでi=4のブロックは実行されない
					}
					System.out.println("1");
				}
				System.out.println("2");
			}
			System.out.println("3");
			System.out.println("");
		}
	}
}

実行結果

1
2
3

2
3

3

ドキュメント

クラスとか URL
List https://docs.oracle.com/javase/jp/9/docs/api/java/util/List.html
ArrayList https://docs.oracle.com/javase/jp/9/docs/api/java/util/ArrayList.html
String https://docs.oracle.com/javase/jp/9/docs/api/java/lang/String.html

misc

クラスを使うために何をimportすればよいか

APIドキュメントのページで、クラス名の2行下のあたりにある表現をimportする。
例えば、java.nio.file.Filesであればimport java.nio.file.Filesとする。

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?