In Java, How Do I Split A String?

Introduction

You will discover in this article how to divide a string in Java. In Java, the built-in method split() is used to divide a string.

Example
import java.util.*;
class SplitStringExample {
    public static void main(String args[]) {
        // Input String
        String inputString = "Happy Learning&Happy Coding";
        // We divided our contributions here. Character by string
        String str[] = inputString.split("&");
        for (String str1: str) {
            System.out.println(str1);
        }
    }
}
Output

Conclusion

We learned how to divide a string in Java in this blog. I appreciate your time and hope you enjoyed it.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories