gpt4 book ai didi

java - 当底层没有流时是否需要关闭Scanner?

转载 作者:行者123 更新时间:2023-12-02 11:23:50 24 4
gpt4 key购买 nike

直接从此扫描仪 API :

String input = "1 fish 2 fish red fish blue fish";
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
s.close();

最佳答案

First we make our habits; then our habits make us.

我会说关闭流,因为养成像在 finally block 中关闭资源这样的习惯是有意义的。

关于java - 当底层没有流时是否需要关闭Scanner?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17945683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com