不使用构造器, 用静态工厂方法表示
返回的可能是素数:
Random random = new Random();
BigInteger bigInteger = BigInteger.probablePrime(4, random);
System.out.println(bigInteger);
输出: 13
from-类型转换方法:
Instant inst = Instant.now();
System.out.println(inst);
Date from = Date.from(inst);
System.out.println(from);
输出:
// 2021-11-22T13:52:52.639Z
// Mon Nov 22 21:52:52 CST 2021
of-聚合方法:
enum Season {
JACK, QUEEN, KING, SPRING, SUMMER, Fall, WINTER;
}
EnumSet<Season> jack = EnumSet.of(Season.JACK, Season.QUEEN, Season.KING);
System.out.println(jack);
输出: [JACK, QUEEN, KING]
valueOf:
BigInteger bigInteger = BigInteger.valueOf(Integer.MAX_VALUE);
System.out.println(bigInteger);
输出: 2147483647
instance或者getInstance
StackWalker luke = StackWalker.getInstance(option);
这个好像是jdk9以及之后才有的, 我没有实验
create或者newInstance
Object o = Array.newInstance(Integer.class, 3);
Array.set(o, 2, 4);
System.out.println(Array.get(o, 2));
结果: 4
getType:
Path path = Paths.get("H:\\图片\\p\\80120998_p0.png");
FileStore fileStore = Files.getFileStore(path);
System.out.println(fileStore.name());
System.out.println(fileStore.getTotalSpace());
newType
Path path = Paths.get("H:\\图片\\p\\80120998_p0.png");
BufferedReader br = Files.newBufferedReader(path);
type
Vector v = new Vector();
v.add(1); v.add(2); v.add(4); v.add(3);
ArrayList list = Collections.list(v.elements());
System.out.println(list);
结果: [1, 2, 4, 3]