【clear】 This method is used to delete all the elements of ArrayList. Use as follows. Variable name.clear ();
ArrayList "array" used in Java (add) times Delete all elements with the clear method.
ArrayList<String> array = new ArrayList<String>();
array.add ("Japanese"); array.add ("English"); array.add ("French"); array.add ("Chinese"); array.add ("German");
System.out.println(array);
[Japanese, English, French, Chinese, German]
Delete all the elements of ArrayList.
array.clear();
System.out.println(array);
The output in the list is as follows.
[]
All the values of the element have been deleted and nothing is displayed.
Recommended Posts