This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class MapSample { | |
public static void main(String[] args) { | |
// キーが文字列、値が文字列のマップを作成(インスタンス化) | |
Map<String, String> addressBook = new HashMap<String, String>(); | |
// キーと値をペアで登録する。 | |
addressBook.put("taro", "taro@example.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class ListSample { | |
public static void main(String[] args) { | |
// 文字列のリストを作成(インスタンス化) | |
List<String> stringList = new ArrayList<String>(); | |
// 文字列をリストに追加する | |
stringList.add("文字列1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Example { | |
// [OK] aに値が入っているのでエラーにならない。 | |
public int example01() { | |
int a; | |
a = 1; | |
return a; | |
} | |
// [NG] aに値が入っていないのでエラーになる。 |