アレックス:
変換する何らかの方法がある2d Collection
には1d
?
出力は次のようになります。 [[hello, hallo], [hi]]
requieredは以下のとおりです。 [hello,hallo,hi]
私のしてみてください。
Collection<Collection<String>> st = new ArrayList<>();
Collection<String> co1 = new ArrayList<>();
Collection<String> co2 = new ArrayList<>();
co1.add("hello");
co1.add("hallo");
co2.add("hi");
st.add(co1);
st.add(co2);
System.out.println(st);
エリトリア:
:あなたがJava8 +を使用している場合は、のようなものを使用することができます
Collection<String> result = st.stream().flatMap(Collection::stream).collect(Collectors.toList());
しかし、私は別にここに重複を扱わないことに注意してください。