如何将逗号分隔 Java 字符串转换为数组。


是的,使用 String.split() 方法即可实现。请看下面的示例 −

示例

public class Tester {
   public static void main(String[] args) {
      String text = "This,is,a,comma,seperated,string.";
      String[] array = text.split(",");
      for(String value:array) {
         System.out.print(value + " ");
      }
   }
}

输出

This is a comma seperated string.

更新时间: 24-2-2020

6K+ 浏览量

开始您的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.