This is interesting, so here are a few tests with the output:
static void test(String... args) { Set<String> s =new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); s.addAll(Arrays.asList( "a","b","c")); s.removeAll(Arrays.asList(args)); System.out.println(s); } public static void main(String[] args) { test("C"); output: [a, b] test("C", "A"); output: [b] test("C", "A","B"); output: [a, b, c] test("B","C","A"); output: [a, b, c] test("K","C"); output: [a, b] test("C","K","M"); output: [a, b, c] !! test("C","K","A"); output: [a, b, c] !! }
Now, without a comparator, it works just like a sorted HashSet<String>() :
static void test(String... args) { Set<String> s = new TreeSet<String>();// s.addAll(Arrays.asList( "a","b","c")); s.removeAll(Arrays.asList(args)); System.out.println(s); } public static void main(String[] args) { test("c"); output: [a, b] test("c", "a"); output: [b] test("c", "a","b"); output: [] test("b","c","a"); output: [] test("k","c"); output: [a, b] test("c","k","m"); output: [a, b] test("c","k","m"); output: [a, b] }
Now from the documentation:
public boolean removeAll (collection c)
Removes from this set all its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric difference of the sets of two sets.
This implementation determines which one is smaller and the specified collection by calling the size method for each. If this set has fewer elements, then the implementation iterates over this, set it, checking each element returned by the iterator, in turn, to ensure that it is contained in the specified collection. If so, it is removed from this set using the iterator removal method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set every element returned by the iterator using this set deletion method.
Source