首页javastringJava Data Type - 如何将字符串拆分成子字符串

Java Data Type - 如何将字符串拆分成子字符串

我们想知道如何将字符串拆分成子字符串。

Use the split() method to split a string into multiple strings.

Splitting is performed using a delimiter.

The split() method returns an array of String.

public class Main { public static void main(String[] args) { String str = "A,B,C,D"; // Split str using a comma as the delimiter String[] parts = str.split(","); // Print the the string and its parts System.out.println(str); for (String part : parts) { System.out.println(part); } } }