2017-07-03 66 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", " ", "/"); 
} 

正如您所看到的列表小写和数字也是其他许多列表的一部分。我试过使用.addAll();但它不起作用。JAVA - 如何结合两个列表?

有没有其他方法可以将其他列表添加到另一个列表中?谢谢!

+5

'中的addAll()'在'Arrays.asList()'创建的列表上不起作用:这是一个固定大小的列表。不过,你可以使用'addAll'来添加到'ArrayList'(在许多其他类型的列表中)。 –

+0

如果你不想重复,你可能想使用集合而不是列表。 – worpet

回答

1

如果您使用的是Java 8再试试下面的代码

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