gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:48:43 25 4
gpt4 key购买 nike

我有两个列表,例如

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com