Counting Characters in a String with Java

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 3K views
G01
Science Advisor
Gold Member
Messages
2,709
Reaction score
19
I need java to read a string and count how many characters are in it. I know there's some class that can do this. What is it?
 
Physics news on Phys.org
"Read a string?" From standard input?

Use e.g.

String s = System.in.readLine();
int n = s.length();

- Warren