2017-07-03 7 views
-1
public class Identifiers { 
    public List<String> lowercase = Arrays.asList ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z"); 
    public List<String> uppercase = Arrays.asList ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J" 
             , "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" 
             , "W", "X", "Y", "Z"); 
    public List<String> number = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); 

} 
public class ReservedSymbolsDelims { 
    public List<String> delim_arithop = Arrays.asList ("nl", "tab", " ", "(", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); 
    public List<String> delim_5 = Arrays.asList ("nl", "tab", " ", "(", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\""); 
    public List<String> delim_6 = Arrays.asList ("nl", "tab", " ", "a", "b", "c" ,"d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); 
    public List<String> incop = Arrays.asList ("nl", "tab", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", ","); 
    public List<String> delim_7 = Arrays.asList ("nl", "tab", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "+", "-"); 
    public List<String> delim_8 = Arrays.asList (",", ".", "nl", "tab", " ", "!", "=", ")", ">", "<", "+", "-", "*", "/", "%"); 
    public List<String> delim_9 = Arrays.asList ("nl", "tab", " ", ".", ",", ")", "!", "=", "+", "-", "*", "/", "%", ">", "<" 
             , "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" 
             , "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v" 
             , "w", "x", "y", "z", "]"); 
    public List<String> delim_10 = Arrays.asList ("nl", "tab", " ", "/"); 
} 

Wie Sie sehen können, sind die Liste Kleinbuchstaben und Nummer auch Teil der anderen zahlreichen Listen. Ich habe versucht, die .addAll(); aber es hat nicht funktioniert.JAVA - Wie kombiniere ich zwei Listen?

Gibt es eine andere Möglichkeit, andere Liste zu einer anderen Liste hinzuzufügen? Vielen Dank!

+5

'addAll()' funktioniert nicht auf einer Liste, die von 'Arrays.asList()' erstellt wurde: es ist eine Liste fester Größe. Sie können jedoch 'addAll' verwenden, um zu einer' ArrayList' (neben vielen anderen Arten von Listen) hinzuzufügen. –

+0

Wenn Duplikate niemals benötigt werden, kannst Du Sets anstelle von Listen verwenden. – worpet

Antwort

1

Wenn Sie mit Java 8 dann versuchen, den Code unten

List<String> mergelist = Stream.of(lowercase, number) 
     .flatMap(List::stream) 
     .collect(Collectors.toList()); 
Verwandte Themen