JAVA字串截取

●利用split函数:


  1. String s = new String("2_8_7_4_3_9_1");
  2. String[] arr = s.split("_");

●利用StringTokenizer类:




  1. String s = new String("2_8_7_4_3_9_1");
  2. StringTokenizer commaToker = new StringTokenizer(s, "_");
  3. String[] arr = new String[commaToker.countTokens()];

你可能感兴趣的:(java,String)