如何将 List<List<String>>中包含相同元素的List进行搜索重组

  • 假设一个List里面包含多个List:
    <"apple", "banana">,<"ball", "pen"> <"apple", "orange">, <"grape", "orange">,<"paper","ruler">,<"ink","pen">
    如何将每个List进行重复比对,并将含有相同元素的List合并,最后形成一个新的List>:
    <"apple","banana","orange","grape">,,<"paper","ruler">

    也可理解为:"A=B","C=D","A=E","F=E","G=H","I=D" => 
    "A=B=E=F","C=D=I","G=H"

    请诸位不吝指教,谢谢!


九州编程
浏览 437回答 3
3回答

翻过高山走不出你

(1)Colletions.disjoint来判断是否有交集(2)在有交集的时候进行合并,合并的时候转换为不重复的集合类Set,使用Set的addAll方法合并
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java