Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java9を迎えた今こそ!Java本格(再)入門

2,775 views

Published on

JJUG CCC 2017 FALLで発表した資料です。
#ccc_g3

Published in: Technology
  • Be the first to comment

Java9を迎えた今こそ!Java本格(再)入門

  1. 1. 
 
 Acroquest Technology Co., Ltd.

  2. 2. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 Java 
 Chapter 7 
 Chapter 8 
 Chapter 9 
 Chapter 12 
 Acroquest Technology 
 - 2017 3 
 2Twitter: @omochiya -
  3. 3. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 3 
 

  4. 4. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 4 
 
 
 

  5. 5. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1.Introduction 2.Java 1.4 -> 5.0 3.Java 5.0 -> 7 4.Java 7 -> 8 5.Java 8 -> 9 6.Java 9 -> Future 5
  6. 6. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 6
  7. 7. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 7
  8. 8. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 8 CSV File 2017-09-25,100,123456,Acroquest, 2017-10-02,100,-28980, , 2017-10-03,100,-17712, , 2017-10-20,100,3000000,gihyo, 2017-10-25,100,200000,Acroquest, 
 , , , , etc
  9. 9. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 9
  10. 10. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 10 List read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List list = new ArrayList(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8")); String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = df.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx); } } catch (ParseException e) { throw new RuntimeException("failed to parse date", e); } catch (IOException e) { throw new RuntimeException("failed to read file: " + fileName, e); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { // ignore } } return list; } CSV
  11. 11. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 11 List read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List list = new ArrayList(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(
 new FileInputStream(fileName), "UTF-8")); CSV
  12. 12. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2/3 12 String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = df.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx);
 } CSV
  13. 13. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 3/3 13 } catch (ParseException e) { throw new RuntimeException("failed to parse date", e); } catch (IOException e) { throw new RuntimeException("failed to read file: " + fileName, e); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { // ignore } } return list; } finally close CSV
  14. 14. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 14 class Transaction { Date date; String accountId; Integer amount; String name; String note; public Transaction() { } public Transaction(Date date, String accountId, Integer amount, String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } public String toString() { return date + " " + accountId + " " + amount + " " + name + " " + note; } } CSV
  15. 15. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 1/2 15 class Transaction { Date date; String accountId; Integer amount; String name; String note; public Transaction() { } CSV
  16. 16. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 2/2 16 public Transaction(Date date, String accountId, Integer amount, 
 String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } public String toString() { return date + " " + accountId + " " + amount + " " + name + " " + note; } } CSV
  17. 17. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 17 List list = read(fileName); int sum = 0; for (int i = 0; i < list.size(); i++) { Transaction tx = (Transaction) list.get(i); sum += tx.amount; } System.out.println(sum); CSV
  18. 18. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 6 18 List list = read(fileName); for (int i = 0; i < list.size(); i++) { Transaction tx = (Transaction) list.get(i); Calendar cal = Calendar.getInstance(); cal.setTime(tx.date); if (cal.get(Calendar.MONTH) == 5) { System.out.println(tx); } } 0 CSV
  19. 19. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 19
  20. 20. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 20
  21. 21. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 21
  22. 22. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 22 List read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List list = new ArrayList(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(
 new FileInputStream(fileName), "UTF-8")); CSV
  23. 23. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 23 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<Transaction>(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(
 new FileInputStream(fileName), "UTF-8")); CSV
  24. 24. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 24 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<Transaction>(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(
 new FileInputStream(fileName), "UTF-8")); Generics 
 → 
 → CSV
  25. 25. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 25 List list = read(fileName); int sum = 0; for (int i = 0; i < list.size(); i++) { Transaction tx = (Transaction) list.get(i); sum += tx.amount; } System.out.println(sum); CSV
  26. 26. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 26 List<Transaction> list = read(fileName); int sum = 0; for (Transaction tx : list) { sum += tx.amount; } System.out.println(sum); CSV
  27. 27. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 27 List<Transaction> list = read(fileName); int sum = 0; for (Transaction tx : list) { sum += tx.amount; } System.out.println(sum); CSV for 
 →
  28. 28. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 28
  29. 29. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 2/2 29 public Transaction(Date date, String accountId, Integer amount, 
 String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } public String toString() { return date + " " + accountId + " " + amount + " " + name + " " + note; } } CSV
  30. 30. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 2/2 30 public Transaction(Date date, String accountId, Integer amount, 
 String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } @Override public String toString() { return date + " " + accountId + " " + amount + " " + name + " " + note; } } CSV
  31. 31. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction 2/2 31 public Transaction(Date date, String accountId, Integer amount, 
 String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } @Override public String toString() { return date + " " + accountId + " " + amount + " " + name + " " + note; } } 
 → Override CSV
  32. 32. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 32
  33. 33. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 33
  34. 34. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 34
  35. 35. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 35
  36. 36. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 36 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<Transaction>(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(
 new FileInputStream(fileName), "UTF-8")); CSV
  37. 37. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 37 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { CSV
  38. 38. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 38 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { CSV
  39. 39. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 39 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { try-with-resoureces 
 try ( ) close 
 → 
 → 
 CSV
  40. 40. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 40
  41. 41. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 41 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { Files nio2 CSV
  42. 42. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1/3 42 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { String Charset 
 StandardCharsets 
 → CSV
  43. 43. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 3/3 43 } catch (ParseException e) { throw new RuntimeException("failed to parse date", e); } catch (IOException e) { throw new RuntimeException("failed to read file: " + fileName, e); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { // ignore } } return list; } CSV
  44. 44. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 3/3 44 } catch (ParseException | IOException e) { throw new RuntimeException("failed to parse date or read file”, e); } return list; } catch 
 CSV
  45. 45. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 45
  46. 46. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 46
  47. 47. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 47
  48. 48. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 48
  49. 49. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 49
  50. 50. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 50
  51. 51. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction toString 51 class Transaction { Date date; String accountId; Integer amount; String name; String note; public Transaction() { } public Transaction(Date date, String accountId, Integer amount, String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } CSV
  52. 52. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction toString 52 class Transaction { LocalDate date; String accountId; Integer amount; String name; String note; public Transaction() { } public Transaction(LocalDate date, String accountId, Integer amount, String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } CSV
  53. 53. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 Transaction toString 53 class Transaction { LocalDate date; String accountId; Integer amount; String name; String note; public Transaction() { } public Transaction(LocalDate date, String accountId, Integer amount, String name, String note) { this.date = date; this.accountId = accountId; this.amount = amount; this.name = name; this.note = note; } Date and Time API
 →LocalDate 
 LocalDateTime LocalTime 
 OffsetDateTime ZonedDateTime 
 CSV
  54. 54. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 54
  55. 55. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 55 List<Transaction> read(String fileName) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName), StandardCharsets.UTF_8)) { String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = df.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx);
 } CSV
  56. 56. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 56 List<Transaction> read(String fileName) { // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) { String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx);
 } CSV
  57. 57. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 57 List<Transaction> read(String fileName) { // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) { String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx);
 } UTF-8 Charset 
 ISO 8601 
 CSV
  58. 58. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 58
  59. 59. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 6 59 List<Transaction> list = read(fileName); for (Transaction tx : list) { Calendar cal = Calendar.getInstance(); cal.setTime(tx.date); if (cal.get(Calendar.MONTH) == 5) { System.out.println(tx); } } CSV
  60. 60. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 6 60 List<Transaction> list = read(fileName); for (Transaction tx : list) { if (tx.date.getMonth() == Month.JUNE) { System.out.println(tx); } } CSV
  61. 61. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 - 6 61 List<Transaction> list = read(fileName); for (Transaction tx : list) { if (tx.date.getMonth() == Month.JUNE) { System.out.println(tx); } } enum 
 enum 
 → 0 
 CSV
  62. 62. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 62
  63. 63. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 63
  64. 64. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 64
  65. 65. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 65
  66. 66. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 66 List<Transaction> list = new ArrayList<>(); try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) { String line; while ((line = reader.readLine()) != null) { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; list.add(tx);
 } } catch (ParseException | IOException e) { throw new RuntimeException("failed to parse date or read file”, e); } return list; CSV
  67. 67. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 67 try (Stream<String> stream = Files.lines(Paths.get(fileName))) { return stream .map(line -> { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; return tx; }) .collect(Collectors.toList()); } catch (ParseException | IOException e) { throw new UncheckedIOException("failed to read file", e); } CSV
  68. 68. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 68 try (Stream<String> stream = Files.lines(Paths.get(fileName))) { return stream .map(line -> { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; return tx; }) .collect(Collectors.toList()); } catch (ParseException | IOException e) { throw new UncheckedIOException("failed to read file", e); } 
 Stream 
 List CSV 
 String Transaction
  69. 69. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 69 try (Stream<String> stream = Files.lines(Paths.get(fileName))) { return stream .map(line -> { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; return tx; }) .collect(Collectors.toList()); } catch (ParseException | IOException e) { throw new UncheckedIOException("failed to read file", e); } Lambda CSV
  70. 70. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1 70 // List<Transaction> list = read(fileName); // for (Transaction tx : list) { System.out.println(tx); } // int sum = 0; for (Transaction tx : list) { sum += tx.amount; } System.out.println(sum); CSV
  71. 71. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1 71 // read(fileName).stream() .forEach(System.out::println); // int sum = read(fileName).stream() .mapToInt(tx -> tx.amount) .sum(); System.out.println(sum); CSV
  72. 72. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1 72 // read(fileName).stream() .forEach(System.out::println); // int sum = read(fileName).stream() .mapToInt(tx -> tx.amount) .sum(); System.out.println(sum); int CSV 

  73. 73. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1 73 // read(fileName).stream() .forEach(System.out::println); // int sum = read(fileName).stream() .mapToInt(tx -> tx.amount) .sum(); System.out.println(sum); Lambda CSV
  74. 74. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 74 // 6 
 for (Transaction tx : list) { if (tx.date.getMonth() == Month.JUNE) { System.out.println(tx); } } CSV
  75. 75. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 75 // 6 read(fileName).stream() .filter(tx -> tx.date.getMonth() == Month.JUNE) .forEach(System.out::println); CSV
  76. 76. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 76 // 6 read(fileName).stream() .filter(tx -> tx.date.getMonth() == Month.JUNE) .forEach(System.out::println); 6 filter CSV
  77. 77. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 77 // 6 read(fileName).stream() .filter(tx -> tx.date.getMonth() == Month.JUNE) .forEach(System.out::println); Lambda
  78. 78. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 78
  79. 79. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 79
  80. 80. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 80
  81. 81. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 81
  82. 82. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 82
  83. 83. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 83
  84. 84. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 84
  85. 85. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 85
  86. 86. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 86
  87. 87. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 87
  88. 88. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 88
  89. 89. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 89
  90. 90. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 90 try (Stream<String> stream = Files.lines(Paths.get(fileName))) { return stream .map(line -> { String[] s = line.split(","); Transaction tx = new Transaction(); tx.date = LocalDate.parse(s[0]); tx.accountId = s[1]; tx.amount = Integer.valueOf(s[2]); tx.name = s[3]; tx.note = s[4]; return tx; }) .collect(Collectors.toList()); } catch (ParseException | IOException e) { throw new UncheckedIOException("failed to read file", e); } 
 String Transaction List
  91. 91. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 1 91 // read(fileName).stream() .forEach(System.out::println); // int sum = read(fileName).stream() .mapToInt(tx -> tx.amount) .sum(); System.out.println(sum); 
 int
  92. 92. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 2 92 // 6 read(fileName).stream() .filter(tx -> tx.date.getMonth() == Month.JUNE) .forEach(System.out::println); 6 filter
  93. 93. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 93
  94. 94. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 94
  95. 95. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 95
  96. 96. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 96
  97. 97. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 97
  98. 98. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 98
  99. 99. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 99
  100. 100. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 100
  101. 101. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 101
  102. 102. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 JShell 102 // jshell> List<Integer> intList = List.of(1, 2, 3); intList ==> [1, 2, 3] jshell> List<String> strList = List.of("aaa,", "bbb", “ccc"); strList ==> [aaa,, bbb, ccc] jshell> intList.add(4); | java.lang.UnsupportedOperationException thrown: | at ImmutableCollections.uoe (ImmutableCollections.java:71) ( )
  103. 103. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 JShell 103 // jshell> Map<Integer, String> map = 
 Map.of(1, "aaa", 2, "bbb", 3, “ccc"); map ==> {1=aaa, 2=bbb, 3=ccc} jshell> map.put(4, "ddd"); | java.lang.UnsupportedOperationException thrown: | at ImmutableCollections.uoe (ImmutableCollections.java:71) ( )
  104. 104. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 104
  105. 105. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 105
  106. 106. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 106 // var str = “Hello”; final var MAXIMUM = 100L; // NG var array = {1, 2, 3}; var list = new ArrayList<>();
  107. 107. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 107
  108. 108. Copyright © Acroquest Technology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 108

×