Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leading whitespace while using string.split()

here's the code that i am using to split the string

str = "1234".split("") ; 
System.out.println(str.length) ; //this gives 5

there is an extra whitespace added just before 1 i.e str[0]=" " How to split this string without having the leading whitespace.

like image 231
Pdksock Avatar asked Jan 25 '26 03:01

Pdksock


1 Answers

Try this:

char[] str = "1234".toCharArray();
System.out.println(str.length) ;
like image 151
Achintya Jha Avatar answered Jan 26 '26 18:01

Achintya Jha