「Java」removeAll()でリストの要素を複数削除する

1.複数要素を削除する

       String city[] = {"tokyo","oosaka","beijing","london","fukuoka"};

        List<String> kk = new ArrayList<>(Arrays.asList(city));

        List<String> target = new ArrayList<>();
        Collections.addAll(target,"london","fukuoka");

        kk.removeAll(target);

2.すべて要素を削除する

        String city[] =  {"tokyo","oosaka","beijing","london","fukuoka"};

        List<String> target = new ArrayList<>(Arrays.asList(city));

        target.clear();

 

Java

Posted by arkgame