java: List of String Arrays and remove

前端 未结 4 712
我在风中等你
我在风中等你 2021-01-11 19:01

In a test like this:

    @Test
    public void test() {
        List l = new LinkedList();
        l.add(new String [] {\"tes         


        
4条回答
  •  庸人自扰
    2021-01-11 19:17

    By the way, Java 8 introduces a new removeIf method that removes all of the elements of this collection that satisfy the given predicate

    It can be used to easily remove an array of strings from the list:

    List l = new LinkedList();
    l.add(new String [] {"test", "123"});
    l.add(new String [] {"test", "456"});
    l.add(new String [] {"test", "789"});
    
    String[] newArray = new String[] {"test", "456"};
    l.removeIf(array -> Arrays.equals(array, newArray));
    

提交回复
热议问题