How to split a string with whitespace chars at the beginning?

后端 未结 4 816
青春惊慌失措
青春惊慌失措 2021-01-12 14:43

Quick example:

public class Test {
    public static void main(String[] args) {
        String str = \"   a b\";
        String[] arr = str.split(\"\\\\s+\")         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-12 15:29

    Instead of trimming, you could just add an if to check if a string is empty or not.

提交回复
热议问题