List<String> list = List.of(“A”, “B”, “C”, “D”);
Map<String, Integer> map = Map.of(“A”, 10, “B”, 20);


(
(7)








Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection("URL", "UserName", "Password");
stmt = conn.createStatement();
returning = stmt.executeUpdate(sql);
} catch (SQLException ex1) {
ex1.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException ex2) {
ex2.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex3) {
ex3.printStackTrace();
}
}














try (Connection conn =
DriverManager.getConnection("URL", "UserName", "Password")) {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
returning = stmt.executeUpdate();
}
} catch (SQLException ex) {
ex.printStackTrace();
}






@Test
public void TryWithResourceを使う() {
System.out.println("TryWithResourceを使う ------------");
List<String> lines = new ArrayList<>();
File file = new File(url.getPath());
try (FileReader fr = new FileReader(file);
BufferedReader bf = new BufferedReader(fr)) {
while (true) {
String line = bf.readLine();
if (line == null) {
break;
}
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
for (String line : lines) {
System.out.println(line);
}
}
// 例
// ファイルの場所を特定
Path path = Paths.get("ファイルパスやURIインスタンス");
// テキストファイルの全行読み込み
Files.readAllLines(path);


// pathAのファイルを作成
Files.createFile(pathA);
// pathAのディレクトリを作成
Files.createDirectories(pathA);
// pathAからpathBにファイルを複製
Files.copy(pathA, pathB);
// pathAからpathBにファイルを移動

Files.move(pathA, pathB);
// pathAを削除
Files.delete(pathA, pathB);
// pathAにテキストを書き込み

List<String> out = ...
Files.write(pathA, out);
// pathAの属性を読み込み(例:ファイルサイズ)
Files.size(pathA);
// pathAの属性を読み込み(例:実行可能か)

Files.isExecutable(pathA);
// pathAの属性を読み込み(例:読み書き可能か)
Files.isReadable(pathA);
Files.isWritable(pathA);
@Test
public void NIO2を使う() {
System.out.println("NIO2を使う ------------");
List<String> lines = new ArrayList<>();
URI uri = URI.create(url.toString());
Path path = Paths.get(uri);
try (BufferedReader bf = Files.newBufferedReader(path)) {
while (true) {
String line = bf.readLine();
if (line == null) {
break;
}
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
for (String line : lines) {
System.out.println(line);
}
}
@Test
public void NIO2を使う_小さなファイル() {
System.out.println("NIO2を使う_ファイルサイズが小さいとき ------------");
List<String> lines = null;
URI uri = URI.create(url.toString());
Path path = Paths.get(uri);
try {
lines = Files.readAllLines(path);
} catch (IOException e) {
e.printStackTrace();
}
for (String line : lines) {
System.out.println(line);
}
}










LocalDateTime.now();           //2017-09-02 13:34:00.000
LocalDate.now();             // 2017-09-02
LocalTime.now();             // 13:34:00.000
LocalDateTime.of(2016, 3, 1, 0, 0); // 2016-03-01 00:00:00.000
LocalDateTime ldt = LocalDateTime.now(); //2017-09-02 13:34:00.000
ldt.getYear();             // 2017
ldt.getDayOfWeek();             // SATURDAY






LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt); //2017-09-02T13:34:00.000
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日h時m分s秒");
System.out.println(dtf.format(ldt)); // 2017年9月2日13時34分0秒




LocalDateTime ldt = LocalDateTime.now(); //2017-09-02 13:34:00.000
ldt = ldt.plusDays(1); //2017-09-03 13:34:00.000
ldt = ldt.minusHours(1); //2017-09-02 12:34:00.000
ldt = ldt.withYear(2019); //2019-09-02 13:34:00.000








LocalTime time1 = LocalTime.of(2, 48);
LocalTime time2 = LocalTime.now();
// time1とtime2の時間差をとる
Duration duration = Duration.between(time1, time2);
System.out.println(time1.toString() + "から" + duration.toMinutes() + "分経過");
LocalDate date1 = LocalDate.of(1980, 8, 20);
LocalDate date2 = LocalDate.now();
// date1とdate2の年月差をとる
Period period = Period.between(date1, date2);
System.out.println(date1.toString() + "から" + period.toTotalMonths() + "ヶ月経過");


// LocalDateTime を使って、LocalDate, LocalTime
LocalDate date = ldt.toLocalDate();
LocalTime time = ldt.toLocalTime();
// LocalDateTime から java.sql.Timestamp
LocalDateTime ldt = LocalDateTime.now();
java.sql.Timestamp sqlTime = java.sql.Timestamp.valueOf(ldt);
// java.sql.Timestamp から LocalDateTime
LocalDateTime ldt = sqlTime.toLocalDateTime();
// java.sql.Date から LocalDate
LocalDate date2 = sqlDate.toLocalDate();
// LocalDate から java.sql.Date
LocalDate ldt = LocalDate.now();
java.sql.Date sqlTime = java.sql.Date.valueOf(ldt);
// LocalDate, LocalTime を使って LocalDateTime
LocalDateTime ldt = LocalDateTime.of(LocalDate.now(), LocalTime.now());
@Test
public void 今日の日付と時刻を作る() {
// 日付の作成
LocalDate date = LocalDate.now();
System.out.println(date);
// 時刻の作成
LocalTime time = LocalTime.now();
  System.out.println(time);
// 今年は何年?
int year = date.getYear();
System.out.println("今年は" + year + "年");
// 今は何時?
int hour = time.getHour();
System.out.println("今は" + hour + "時");
// 今日は何曜日?
DayOfWeek dow = date.getDayOfWeek();
System.out.println("今日は" + dow);
}
@Test
public void 日時の表示方法を加工する() {
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日h時m分s秒");
System.out.println(dtf.format(ldt));
}
@Test
public void 日時を操作する() {
// 2016年3月1日12時30分
LocalDateTime ldt1 = LocalDateTime.of(2016, 3, 1, 12, 30);
System.out.println(ldt1);
// ldt1の一日前のインスタンスを取得
LocalDateTime ldt2 = ldt1.minusDays(1);
System.out.println("一日前は" + ldt2);
// ldt1を2017年に上書きしたインスタンスを取得
LocalDateTime ldt3 = ldt1.withYear(2017);
System.out.println(ldt3);
// ldt3の一日前のインスタンスを取得
LocalDateTime ldt4 = ldt3.minusDays(1);
System.out.println("一日前は" + ldt4);
}
@Test
public void 日時の差を計算する() {
LocalTime time1 = LocalTime.of(2, 48);
LocalTime time2 = LocalTime.now();
// time1とtime2の時間差をとる
Duration duration = Duration.between(time1, time2);
System.out.println(time1.toString() + "から" + duration.toMinutes() + "分経過");
System.out.println(time1.toString() + "から" + duration.toHours() + "時間" + duration.toMinutes() % 60 + "分経過");
// date1には、皆さんの誕生日を入れて下さい
LocalDate date1 = LocalDate.of(1980, 8, 20);
LocalDate date2 = LocalDate.now();
// date1とdate2の年月差をとる
Period period = Period.between(date1, date2);
System.out.println(date1.toString() + "から" + period.toTotalMonths() + "ヶ月経過");
System.out.println("あなたの年齢は" + period.toTotalMonths() / 12 + "歳");
}




List<Integer> list =
Arrays.asList(22, 10, 19, 38);
for (Integer i : list) {
if (i % 2 == 0) {
System.out.println(i);
}
}
List<Integer> list =
Arrays.asList(22, 10, 19, 38);
list.stream()
.filter(i -> i % 2 == 0)
.forEach(i -> System.out.println(i));










list.stream()
.filter( i -> i % 2 == 0 )
.forEach( i -> System.out.println(i) );




















list.stream()
.filter( i -> i % 2 == 0 )
.forEach( i -> System.out.println(i) );
list.stream()
.filter(i -> i % 2 == 0)
.forEach(System.out::println);
























@Test
public void Streamとこれまでの違い() {
List<Integer> nums = Arrays.asList(22, 10, 19, 38);
for (Integer i : nums) {
if (i % 2 == 0) {
System.out.println(i);
}
}
nums.stream()
.filter(i -> i % 2 == 0)
.forEach(i -> System.out.println(i));
}
@Test
public void 長さが5以上の単語だけをListに集める() {
List<String> filterdList = words.stream()
.filter(word -> word.length() >= 5)
.collect(Collectors.toList());
System.out.println(filterdList);
}
@Test
public void 要素を単語の長さに変えてListに集める() {
List<Integer> lengthList = words.stream()
.map(word -> word.length())
.collect(Collectors.toList());
System.out.println(lengthList);
}
@Test
public void 要素を単語の長さに変えてListに集める() {
List<Integer> lengthList = words.stream()
.map(word -> word.length())
.collect(Collectors.toList());
System.out.println(lengthList);
}
@Test
public void 要素を文字のリストに変えてListに集める() {
List<String> chars = words.stream()
.map(word -> word.split(""))
.flatMap(word -> Arrays.stream(word))
.collect(Collectors.toList());
System.out.println(chars);
}
@Test
public void 単語と文字数のMapに集める() {
Map<String, Integer> map = words.stream()
.collect(Collectors.toMap(s -> s, s -> s.length()));
System.out.println(map);
}
@Test
public void 一番短い単語を取得する() {
String defaultStr = "none.";
String ans = words.stream()
.sorted(Comparator.comparing(String::length))
.findFirst()
.orElse(defaultStr);
System.out.println(ans);
}
@Test
public void 一番長い単語を取得する() {
String defaultStr = "none.";
String ans = words.stream()
.sorted(Comparator.comparing(String::length).reversed())
.findFirst()
.orElse(defaultStr);
System.out.println(ans);
}
@Test
public void 単語の長さを合計する() {
int defaultInt = 0;
int ans = words.stream()
.map(word -> word.length())
.reduce(defaultInt, (x, y) -> x + y);
System.out.println(ans);
}
@Test
public void 異なる処理をするStreamを合成して実行する() {
Stream<String> s1 = words.stream()
.filter(word -> word.length() >= 5)
.map(String::toUpperCase);
Stream<String> s2 = words.stream()
.filter(word -> word.length() < 5)
.map(String::toLowerCase);
// ↑ どんなStreamを用意すればいいのか宣言のみ行われる
List<String> ans = Stream.concat(s1, s2)
.collect(Collectors.toList());
// ↑ 終端処理(collect)でs1, s2の内容がすべて実行される
System.out.println(ans);
}








Objects.requireNonNull(str, "strがnull");
@Override
public int compareTo(B other) {
// 小さい順に並び替える
return Integer.compare(x, other.getX());
}




List<String> strs = Arrays.asList("Hello", "Duke");
System.out.println(String.join("_", strs)); //Hello_Duke








@Override
public boolean equals(Object object) {
if (object instanceof A) {
A other = (A) object;
return Objects.equals(x, other.getX())
&& Objects.equals(y, other.getY());
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
A a1 = new A("hello", "world");
A a2 = new A("hello", "world");
assertTrue(a1.equals(a2)); // ← trueになる










String str1 = "a";
Optional<String> o1 = Optional.ofNullable(str1);
String str2 = null;
Optional<String> o2 = Optional.ofNullable(str2);
System.out.println("------------");
// nullじゃないときだけラムダ式が実行される
o1.ifPresent(s -> System.out.println(s));
o2.ifPresent(s -> System.out.println(s));
System.out.println("------------");
// nullの時は "nullです" を返す
System.out.println(o1.orElse("nullです"));
System.out.println(o2.orElse("nullです"));
------------
a
------------
a
nullです







 








Java9直前!最近のJava復習ハンズオン

  • 2.
  • 3.
  • 4.
    
 
 List<String> list =List.of(“A”, “B”, “C”, “D”); Map<String, Integer> map = Map.of(“A”, 10, “B”, 20);
  • 6.
  • 8.
    
 
 
 
 Connection conn =null; Statement stmt = null; try { conn = DriverManager.getConnection("URL", "UserName", "Password"); stmt = conn.createStatement(); returning = stmt.executeUpdate(sql); } catch (SQLException ex1) { ex1.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException ex2) { ex2.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (SQLException ex3) { ex3.printStackTrace(); } } 
 
 
 
 
 

  • 9.
    
 try (Connection conn= DriverManager.getConnection("URL", "UserName", "Password")) { try (PreparedStatement stmt = conn.prepareStatement(sql)) { returning = stmt.executeUpdate(); } } catch (SQLException ex) { ex.printStackTrace(); } 
 
 

  • 10.
    @Test public void TryWithResourceを使う(){ System.out.println("TryWithResourceを使う ------------"); List<String> lines = new ArrayList<>(); File file = new File(url.getPath()); try (FileReader fr = new FileReader(file); BufferedReader bf = new BufferedReader(fr)) { while (true) { String line = bf.readLine(); if (line == null) { break; } lines.add(line); } } catch (IOException e) { e.printStackTrace(); } for (String line : lines) { System.out.println(line); } }
  • 12.
    // 例 // ファイルの場所を特定 Pathpath = Paths.get("ファイルパスやURIインスタンス"); // テキストファイルの全行読み込み Files.readAllLines(path); 

  • 13.
    // pathAのファイルを作成 Files.createFile(pathA); // pathAのディレクトリを作成 Files.createDirectories(pathA); //pathAからpathBにファイルを複製 Files.copy(pathA, pathB); // pathAからpathBにファイルを移動
 Files.move(pathA, pathB); // pathAを削除 Files.delete(pathA, pathB); // pathAにテキストを書き込み
 List<String> out = ... Files.write(pathA, out); // pathAの属性を読み込み(例:ファイルサイズ) Files.size(pathA); // pathAの属性を読み込み(例:実行可能か)
 Files.isExecutable(pathA); // pathAの属性を読み込み(例:読み書き可能か) Files.isReadable(pathA); Files.isWritable(pathA);
  • 14.
    @Test public void NIO2を使う(){ System.out.println("NIO2を使う ------------"); List<String> lines = new ArrayList<>(); URI uri = URI.create(url.toString()); Path path = Paths.get(uri); try (BufferedReader bf = Files.newBufferedReader(path)) { while (true) { String line = bf.readLine(); if (line == null) { break; } lines.add(line); } } catch (IOException e) { e.printStackTrace(); } for (String line : lines) { System.out.println(line); } }
  • 15.
    @Test public void NIO2を使う_小さなファイル(){ System.out.println("NIO2を使う_ファイルサイズが小さいとき ------------"); List<String> lines = null; URI uri = URI.create(url.toString()); Path path = Paths.get(uri); try { lines = Files.readAllLines(path); } catch (IOException e) { e.printStackTrace(); } for (String line : lines) { System.out.println(line); } }
  • 17.
  • 18.
    
 
 
 LocalDateTime.now();           //2017-09-0213:34:00.000 LocalDate.now();             // 2017-09-02 LocalTime.now();             // 13:34:00.000 LocalDateTime.of(2016, 3, 1, 0, 0); // 2016-03-01 00:00:00.000 LocalDateTime ldt = LocalDateTime.now(); //2017-09-02 13:34:00.000 ldt.getYear();             // 2017 ldt.getDayOfWeek();             // SATURDAY
  • 19.
    
 
 
 LocalDateTime ldt =LocalDateTime.now(); System.out.println(ldt); //2017-09-02T13:34:00.000 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日h時m分s秒"); System.out.println(dtf.format(ldt)); // 2017年9月2日13時34分0秒 

  • 20.
    
 LocalDateTime ldt =LocalDateTime.now(); //2017-09-02 13:34:00.000 ldt = ldt.plusDays(1); //2017-09-03 13:34:00.000 ldt = ldt.minusHours(1); //2017-09-02 12:34:00.000 ldt = ldt.withYear(2019); //2019-09-02 13:34:00.000 
 
 
 

  • 21.
    LocalTime time1 =LocalTime.of(2, 48); LocalTime time2 = LocalTime.now(); // time1とtime2の時間差をとる Duration duration = Duration.between(time1, time2); System.out.println(time1.toString() + "から" + duration.toMinutes() + "分経過"); LocalDate date1 = LocalDate.of(1980, 8, 20); LocalDate date2 = LocalDate.now(); // date1とdate2の年月差をとる Period period = Period.between(date1, date2); System.out.println(date1.toString() + "から" + period.toTotalMonths() + "ヶ月経過");
  • 22.
    
 // LocalDateTime を使って、LocalDate,LocalTime LocalDate date = ldt.toLocalDate(); LocalTime time = ldt.toLocalTime(); // LocalDateTime から java.sql.Timestamp LocalDateTime ldt = LocalDateTime.now(); java.sql.Timestamp sqlTime = java.sql.Timestamp.valueOf(ldt); // java.sql.Timestamp から LocalDateTime LocalDateTime ldt = sqlTime.toLocalDateTime(); // java.sql.Date から LocalDate LocalDate date2 = sqlDate.toLocalDate(); // LocalDate から java.sql.Date LocalDate ldt = LocalDate.now(); java.sql.Date sqlTime = java.sql.Date.valueOf(ldt); // LocalDate, LocalTime を使って LocalDateTime LocalDateTime ldt = LocalDateTime.of(LocalDate.now(), LocalTime.now());
  • 23.
    @Test public void 今日の日付と時刻を作る(){ // 日付の作成 LocalDate date = LocalDate.now(); System.out.println(date); // 時刻の作成 LocalTime time = LocalTime.now();   System.out.println(time); // 今年は何年? int year = date.getYear(); System.out.println("今年は" + year + "年"); // 今は何時? int hour = time.getHour(); System.out.println("今は" + hour + "時"); // 今日は何曜日? DayOfWeek dow = date.getDayOfWeek(); System.out.println("今日は" + dow); }
  • 24.
    @Test public void 日時の表示方法を加工する(){ LocalDateTime ldt = LocalDateTime.now(); System.out.println(ldt); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日h時m分s秒"); System.out.println(dtf.format(ldt)); }
  • 25.
    @Test public void 日時を操作する(){ // 2016年3月1日12時30分 LocalDateTime ldt1 = LocalDateTime.of(2016, 3, 1, 12, 30); System.out.println(ldt1); // ldt1の一日前のインスタンスを取得 LocalDateTime ldt2 = ldt1.minusDays(1); System.out.println("一日前は" + ldt2); // ldt1を2017年に上書きしたインスタンスを取得 LocalDateTime ldt3 = ldt1.withYear(2017); System.out.println(ldt3); // ldt3の一日前のインスタンスを取得 LocalDateTime ldt4 = ldt3.minusDays(1); System.out.println("一日前は" + ldt4); }
  • 26.
    @Test public void 日時の差を計算する(){ LocalTime time1 = LocalTime.of(2, 48); LocalTime time2 = LocalTime.now(); // time1とtime2の時間差をとる Duration duration = Duration.between(time1, time2); System.out.println(time1.toString() + "から" + duration.toMinutes() + "分経過"); System.out.println(time1.toString() + "から" + duration.toHours() + "時間" + duration.toMinutes() % 60 + "分経過"); // date1には、皆さんの誕生日を入れて下さい LocalDate date1 = LocalDate.of(1980, 8, 20); LocalDate date2 = LocalDate.now(); // date1とdate2の年月差をとる Period period = Period.between(date1, date2); System.out.println(date1.toString() + "から" + period.toTotalMonths() + "ヶ月経過"); System.out.println("あなたの年齢は" + period.toTotalMonths() / 12 + "歳"); }
  • 28.
  • 29.
    List<Integer> list = Arrays.asList(22,10, 19, 38); for (Integer i : list) { if (i % 2 == 0) { System.out.println(i); } } List<Integer> list = Arrays.asList(22, 10, 19, 38); list.stream() .filter(i -> i % 2 == 0) .forEach(i -> System.out.println(i));
  • 30.
    
 
 
 
 
 list.stream() .filter( i ->i % 2 == 0 ) .forEach( i -> System.out.println(i) ); 
 

  • 34.
  • 35.
  • 36.
    
 
 
 
 list.stream() .filter( i ->i % 2 == 0 ) .forEach( i -> System.out.println(i) ); list.stream() .filter(i -> i % 2 == 0) .forEach(System.out::println);
  • 37.
  • 38.
  • 39.
    @Test public void Streamとこれまでの違い(){ List<Integer> nums = Arrays.asList(22, 10, 19, 38); for (Integer i : nums) { if (i % 2 == 0) { System.out.println(i); } } nums.stream() .filter(i -> i % 2 == 0) .forEach(i -> System.out.println(i)); }
  • 40.
    @Test public void 長さが5以上の単語だけをListに集める(){ List<String> filterdList = words.stream() .filter(word -> word.length() >= 5) .collect(Collectors.toList()); System.out.println(filterdList); }
  • 41.
    @Test public void 要素を単語の長さに変えてListに集める(){ List<Integer> lengthList = words.stream() .map(word -> word.length()) .collect(Collectors.toList()); System.out.println(lengthList); }
  • 42.
    @Test public void 要素を単語の長さに変えてListに集める(){ List<Integer> lengthList = words.stream() .map(word -> word.length()) .collect(Collectors.toList()); System.out.println(lengthList); }
  • 43.
    @Test public void 要素を文字のリストに変えてListに集める(){ List<String> chars = words.stream() .map(word -> word.split("")) .flatMap(word -> Arrays.stream(word)) .collect(Collectors.toList()); System.out.println(chars); }
  • 44.
    @Test public void 単語と文字数のMapに集める(){ Map<String, Integer> map = words.stream() .collect(Collectors.toMap(s -> s, s -> s.length())); System.out.println(map); }
  • 45.
    @Test public void 一番短い単語を取得する(){ String defaultStr = "none."; String ans = words.stream() .sorted(Comparator.comparing(String::length)) .findFirst() .orElse(defaultStr); System.out.println(ans); }
  • 46.
    @Test public void 一番長い単語を取得する(){ String defaultStr = "none."; String ans = words.stream() .sorted(Comparator.comparing(String::length).reversed()) .findFirst() .orElse(defaultStr); System.out.println(ans); }
  • 47.
    @Test public void 単語の長さを合計する(){ int defaultInt = 0; int ans = words.stream() .map(word -> word.length()) .reduce(defaultInt, (x, y) -> x + y); System.out.println(ans); }
  • 48.
    @Test public void 異なる処理をするStreamを合成して実行する(){ Stream<String> s1 = words.stream() .filter(word -> word.length() >= 5) .map(String::toUpperCase); Stream<String> s2 = words.stream() .filter(word -> word.length() < 5) .map(String::toLowerCase); // ↑ どんなStreamを用意すればいいのか宣言のみ行われる List<String> ans = Stream.concat(s1, s2) .collect(Collectors.toList()); // ↑ 終端処理(collect)でs1, s2の内容がすべて実行される System.out.println(ans); }
  • 50.
    
 
 
 
 Objects.requireNonNull(str, "strがnull"); @Override public intcompareTo(B other) { // 小さい順に並び替える return Integer.compare(x, other.getX()); } 
 
 List<String> strs = Arrays.asList("Hello", "Duke"); System.out.println(String.join("_", strs)); //Hello_Duke 
 

  • 51.
    
 
 @Override public boolean equals(Objectobject) { if (object instanceof A) { A other = (A) object; return Objects.equals(x, other.getX()) && Objects.equals(y, other.getY()); } return false; } @Override public int hashCode() { return Objects.hash(x, y); } A a1 = new A("hello", "world"); A a2 = new A("hello", "world"); assertTrue(a1.equals(a2)); // ← trueになる 
 
 
 
 

  • 52.
    String str1 ="a"; Optional<String> o1 = Optional.ofNullable(str1); String str2 = null; Optional<String> o2 = Optional.ofNullable(str2); System.out.println("------------"); // nullじゃないときだけラムダ式が実行される o1.ifPresent(s -> System.out.println(s)); o2.ifPresent(s -> System.out.println(s)); System.out.println("------------"); // nullの時は "nullです" を返す System.out.println(o1.orElse("nullです")); System.out.println(o2.orElse("nullです")); ------------ a ------------ a nullです 
 
 

  • 53.