Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java string split without space

Tags:

java

string

split

I'm trying to split some user input. The input is of the form a1 b2 c3 d4. For each input (eg; a1), how do I split it into 'a' and '1'?

I'm familiar with the string split function, but what do I specify as the delimiter or is this even possible?

Thanks.

like image 741
Triple777er Avatar asked Apr 25 '26 19:04

Triple777er


1 Answers

You could use String#substring()

String a1 = "a1"
String firstLetterStr = a1.substring(0,1);
String secondLetterStr = a1.substirng(1,a1.length());

Similarly,

String c31 = "c31"
String firstLetterStr = c31.substring(0,1);
String secondLetterStr = c31.substirng(1,c31.length());
like image 70
Bala R Avatar answered Apr 27 '26 07:04

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!