[Java] How to use removeAll ()

how to use

[1, 2, 3, 2, 5]From2When5If you want to remove, you can implement it with remove all as follows.

		List<Integer> list = new ArrayList<>();
		list.add(1); list.add(2); list.add(3); list.add(2); list.add(5);
		System.out.println(list);  //=> [1, 2, 3, 2, 5]
		System.out.println(list.removeAll(Arrays.asList(2, 5)));  //=> true
		System.out.println(list);  //=> [1, 3]

important point

list.removeAll(2)You cannot pass elements directly like. (Compile error)




Recommended Posts

[Java] How to use removeAll ()
[Java] How to use Map
How to use java Optional
How to use java class
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
How to use Java HttpClient (Post)
[Java] How to use join method
[Processing × Java] How to use variables
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
Multilingual Locale in Java How to use Locale
How to use Map
[Java] How to use the File class
[Java] How to use the hasNext function
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use submit method (Java Silver)
[Java] How to use the HashMap class
How to use collection_select
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
How to use JUnit 5
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
How to use Dozer.mapper
[Java] How to use the Calendar class
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
How to use Map
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation