如何將逗號分隔 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.
廣告