Is there a better way to combine two string sets in java?

后端 未结 12 1320
天涯浪人
天涯浪人 2020-12-05 01:41

I need to combine two string sets while filtering out redundant information, this is the solution I came up with, is there a better way that anyone can suggest? Perhaps som

12条回答
  •  难免孤独
    2020-12-05 02:25

    http://docs.oracle.com/javase/7/docs/api/java/util/Set.html#addAll(java.util.Collection)

    Since sets can't have duplicates, just adding all the elements of one to the other generates the correct union of the two.

提交回复
热议问题