【问题标题】:How to merge two "strings" with unique values to new String in java? Using converting to arrays or listsjava - 如何将具有唯一值的两个“字符串”合并到java中的新字符串?使用转换为数组或列表
【发布时间】:2023-03-14 23:15:02
【问题描述】:

有人可以帮我解决这个问题吗? 谢谢

String a = 1||2||3
String b = 2||4||5

String c = 1||2||3||4||5|| //Must be uniqe

【问题讨论】:

标签: java arrays list


【解决方案1】:

使用转换为数组或列表?我不知道你的意思。但我建议

String a = "1||2||3";
String b = "2||4||5";
String[] arrayA = a.split("||");
String[] arrayB = b.split("||");
List<String> list = Arrays.asList(arrayA);
list.addAll(Arrays.asList(arrayB));            
System.console().printf(list.stream().distinct().collect(Collectors.joining("||")));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多