2017-04-03 43 views
0

我有兩個列表:如何將兩個列表與舊訂單合併?

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); 

但總是我'ge擬合

[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] 
+2

似乎有什麼不對,你發佈的代碼。可能還有一些其他問題正在進行。 – Sedrick

回答

0

但這項工作做得很好:

//to concat two list 
List<String> result = Stream.concat(list1.stream(), list2.stream()).collect(Collectors.toList()); 

    result.forEach(s->System.out.print(s+" ")); 
+0

確實對不起!但使用concat即時獲得你想要的結果! – mir

+0

你可以檢查這個鏈接,你可以把代碼和編譯在https://www.compilejava.net/ – mir