OnJava8-Examples/references/ImmutableInteger.java

23 lines
651 B
Java
Raw Permalink Normal View History

2015-09-07 11:44:36 -06:00
// references/ImmutableInteger.java
// (c)2021 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -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
// The Integer class cannot be changed
2015-06-15 17:47:35 -07:00
import java.util.*;
2017-01-21 11:39:19 -08:00
import java.util.stream.*;
2015-06-15 17:47:35 -07:00
public class ImmutableInteger {
public static void main(String[] args) {
2020-10-07 17:06:42 -06:00
@SuppressWarnings("deprecation")
2017-01-21 11:39:19 -08:00
List<Integer> v = IntStream.range(0, 10)
.mapToObj(Integer::new)
.collect(Collectors.toList());
System.out.println(v);
2015-06-15 17:47:35 -07:00
// But how do you change the int
// inside the Integer?
}
2015-09-07 11:44:36 -06:00
}
2017-01-21 11:39:19 -08:00
/* Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
*/