Acroquest Technology Co., Ltd.

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
-
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
3




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








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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


6
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
7
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
9
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
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
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
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
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
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
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


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


21
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
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
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
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
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
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 

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


28
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
32
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
33
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


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


35
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
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


40
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
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


45
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
46
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
47
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


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




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


50
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3








54
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3


58
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3




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




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


65
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
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
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
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
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
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
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


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
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
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3




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




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




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


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


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






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




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




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








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




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






89
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
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
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
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3






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






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








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








96
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
97
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
98
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3




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






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








101
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)
( )
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)
( )
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
104
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
105
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<>();
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3
107
Copyright © Acroquest Technology Co., Ltd. All rights reserved.
#ccc_g3








108

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

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

  • 4.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 4 
 
 
 

  • 5.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 6
  • 7.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 7
  • 8.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 9
  • 10.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 19
  • 20.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 20
  • 21.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 21
  • 22.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 28
  • 29.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 32
  • 33.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 33
  • 34.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 34
  • 35.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 35
  • 36.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 40
  • 41.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 45
  • 46.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 46
  • 47.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 47
  • 48.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 48
  • 49.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 49
  • 50.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 50
  • 51.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 54
  • 55.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 58
  • 59.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 62
  • 63.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 63
  • 64.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 64
  • 65.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 65
  • 66.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 78
  • 79.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 79
  • 80.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 80
  • 81.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 81
  • 82.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 82
  • 83.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 83
  • 84.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 84
  • 85.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 85
  • 86.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 86
  • 87.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 87
  • 88.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 88
  • 89.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 89
  • 90.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 93
  • 94.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 94
  • 95.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 95
  • 96.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 96
  • 97.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 97
  • 98.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 98
  • 99.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 99
  • 100.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 100
  • 101.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 101
  • 102.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 104
  • 105.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 105
  • 106.
    Copyright © AcroquestTechnology 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.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 107
  • 108.
    Copyright © AcroquestTechnology Co., Ltd. All rights reserved. #ccc_g3 
 
 
 
 108