我有两个清单:
private static final List<String> NUMERIC_VALUES = Arrays.asList("100","5","1","0","1111111","6","11","12","50","99","101");
private static final List<String> ALPHANUMERIC_VALUES = Arrays.asList("10A0", "1B1", "6A", "A0", "A1", "ABC", "C5", "T-1", "TT", "TTT",
"434/32145", "434/12354", "32654B", "32654A", "32654B/1");
合并后我会:
[100, 5, 1, 0, 1111111, 6, 11, 12, 50, 99, 101, 10A0, 1B1, 6A, A0, A1, ABC, C5, T-1, TT, TTT, 434/32145, 434/12354, 32654B, 32654A, 32654B/1]
我试过了:
List<String> result = Stream.concat(NUMERIC_VALUES.stream(), ALPHANUMERIC_VALUES.stream()).collect(Collectors.toList());
还有:
List<String> result = new ArrayList<String>();
result.addAll(NUMERIC_VALUES);
result.addAll(ALPHANUMERIC_VALUES);
但我总是得到
[100, 5, 1, 0, 1111111, 6, 11, 12, 50, 99, 101, 10A0, 1B1, 32654A, 32654B, 32654B/1, 434/12354, 434/32145, 6A, A0, A1, ABC, C5, T-1, TT, TTT]
答案 0 :(得分:0)
但这很有效:
//to concat two list
List<String> result = Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList());
result.forEach(s->System.out.print(s+" "));