String s1="Hello World"可以通过s1.split(" ")转换为数组{"Hello","World"}
String s2="System.out.println(s1)"转换为数组{"System","out","println","s1"}

解决方案 »

  1.   

    s2.split(char[]{',',')','('})好像是这样
      

  2.   

    public class Test {
        public static void main(String[] args) throws Exception {
            String str = "System.out.println(s1)";
            String[] strs = str.split("[.()]");
            for(String s : strs) {
                System.out.println(s);
            }
        }
    }
      

  3.   

    我这样做的:
    char[] CHS = { '+', '-', '/', '=', '(', ')', '[', ']', '{', '}', '<',
    '>', ':', '?', ';', ',', '.', '!', '|', '&', '%', '\'', '"',
    ' ', '\n', '\r', '\t' }; // 符号数组
    String regexs = "[" + new String(CHS) + "]";
    String[] arr = source.split(regexs);
    但是一直提示错误:
    java.util.regex.PatternSyntaxException: Unclosed character class near index 28
    [+-/=()[]{}<>:?;,.!|&%'"  ]
                                ^
    28好像是最后的那个],这是怎么回事,而且在CHS数组里面加入乘号*也会报同样的错误
      

  4.   


    String s2="System.out.println(s1)";
         String[] s = s2.split("[.()]");
         for(String s1:s) {
         System.out.println(s1);
         }
      

  5.   

    你想干什么....regexs是符号的字符串,你把那个当作匹配器?