How Do I Split A String In Java?

Introduction

In this blog, you will learn how to split a string in java. We have a built-in function named split() which is used to split a string in java.

Example

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

Output

Split A String In Java 

Conclusion

In this blog, we have seen how to split a string in java. Thanks for reading and I hope you like it. If you have any suggestions or queries about this blog, please share your thoughts. You can read my other blog and articles by clicking here.

Happy learning, friends!