java 如何清除 List<String>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43789338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to clear List<String>
提问by Rytis Vanagas
I need help for list clearing, I taking data from database and I need to clear it after every row.
我需要清除列表的帮助,我从数据库中获取数据,并且需要在每一行之后清除它。
for (HashMap<String, String> hashMap : data16) {
List<String> arrayList111 = new ArrayList<>();
for (String value1 : hashMap.values()) {
// arrayList111.removeAll(arrayList111);
uzsakymas111[l] = value1 ;
Collections.addAll(arrayList111, uzsakymas111);
arrayList111.removeAll(Collections.singleton(null));
String vupvup = Integer.toString(l+1);
expandableListDetail.put(vupvup,arrayList111);
l++;
}
}
Can you say me how and where I have to use .clear() function ,because now its not helping.
你能告诉我如何以及在哪里使用 .clear() 函数,因为现在它没有帮助。
回答by Sean Stayns
You can use
您可以使用
arrayList111.clear();
or
或者
arrayList111 = new ArrayList<>();
The second way is faster and the gc clears the memory.
第二种方式更快,gc 会清除内存。
回答by Anshul Sharma
you can use arrayList111.clear();
to clear list.
您可以使用arrayList111.clear();
清除列表。