java - 任何与保留所有功能相反的方法?

标签 java collections

我有两个列表,例如

List<String> list1 = new ArrayList<String>(Arrays.asList("A", "B", "C"));
List<String> list2 = new ArrayList<String>(Arrays.asList("A"));

List<String> result = list1.(SomeMethod)(list2)必须返回 result = {"B","C"}

有这样的方法吗?

最佳答案

list1.removeAll(list2)

/**
 * Removes from this list all of its elements that are contained in the
 * specified collection (optional operation).
 *
 * @param c collection containing elements to be removed from this list
 * @return <tt>true</tt> if this list changed as a result of the call
 * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
 *         is not supported by this list
 * @throws ClassCastException if the class of an element of this list
 *         is incompatible with the specified collection (optional)
 * @throws NullPointerException if this list contains a null element and the
 *         specified collection does not permit null elements (optional),
 *         or if the specified collection is null
 * @see #remove(Object)
 * @see #contains(Object)
 */
boolean removeAll(Collection<?> c);

关于java - 任何与保留所有功能相反的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32065313/

相关文章:

Java原子操作

java - 使用依赖注入(inject) Spring 的好处

java - 运行时异常 : Unable to instantiate activity

c# - Scala collection 的seq/par/view/force 是否可以被视为违反统一返回类型原则?

c# - 删除集合中的重复值

c# - 如何安全地迭代 IAsyncEnumerable 以向下游发送集合以批量处理消息

java - openapi-code-generator 3.3.4 不读取标签并且 API 类名不是预期的

scala - Scala 2.9 和 Actors 中的并行集合

Java - 固定大小列表和指定初始容量的列表之间的差异

java - 如何让一个 "Don' t再次显示这个警告信息”对话框弹出