2016-01-25 18:05:55 -08:00
|
|
|
// references/SimplerMutableInteger.java
|
2021-01-31 15:42:31 -07:00
|
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
2016-01-25 18:05:55 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-01-25 18:05:55 -08:00
|
|
|
// A trivial wrapper class
|
|
|
|
import java.util.*;
|
2017-01-21 11:39:19 -08:00
|
|
|
import java.util.stream.*;
|
2016-01-25 18:05:55 -08:00
|
|
|
|
|
|
|
class IntValue2 {
|
|
|
|
public int n;
|
2017-05-01 14:33:10 -06:00
|
|
|
IntValue2(int n) { this.n = n; }
|
2016-01-25 18:05:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public class SimplerMutableInteger {
|
|
|
|
public static void main(String[] args) {
|
2017-01-21 11:39:19 -08:00
|
|
|
List<IntValue2> v = IntStream.range(0, 10)
|
|
|
|
.mapToObj(IntValue2::new)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
v.forEach(iv2 ->
|
|
|
|
System.out.print(iv2.n + " "));
|
2016-01-25 18:05:55 -08:00
|
|
|
System.out.println();
|
2017-01-21 11:39:19 -08:00
|
|
|
v.forEach(iv2 -> iv2.n += 1);
|
|
|
|
v.forEach(iv2 ->
|
|
|
|
System.out.print(iv2.n + " "));
|
2016-01-25 18:05:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
|
|
|
0 1 2 3 4 5 6 7 8 9
|
|
|
|
1 2 3 4 5 6 7 8 9 10
|
|
|
|
*/
|