0

How to get first char in string in Java

I have some string and I have to get zero index of string. But it throws error, strings isn't indexed and arrays indexed only. How yo get zero index of string?

3rd Jul 2021, 11:44 AM
a SnowFlake
a SnowFlake - avatar
2 Answers
+ 4
You can use charAt(index) or toCharArray() method.
3rd Jul 2021, 11:53 AM
Ciro Pellegrino
Ciro Pellegrino - avatar
+ 4
char ch = string.charAt(0);
3rd Jul 2021, 11:52 AM
Jan
Jan - avatar