我有一个文本文件,我需要逐行阅读并在每行上做一些处理。字符串的垃圾回收
ConcurrentMap<String, String> hm = new ConcurrentHashMap<>();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("filename.txt");
InputStreamReader stream = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(stream);
while(true)
{
line = reader.readLine();
if (line == null) {
break;
}
String text = line.substring(0, line.lastIndexOf(",")).trim();
String id = line.substring(line.lastIndexOf(",") + 1).trim();
hm.put(text,id);
}
我需要知道,当将在substring()
和trim()
操作创建的字符串是垃圾回收? 另外,字符串line
呢?
请编辑您的问题,并向我们展示您如何使用在'while'循环中填充的地图。 –