How to get the length of a string in Java
To get a length of a string, we can use the built-in length()
method in Java.
Here is an example:
String name = "corejava" ;
System.out.println(name.length()); // 8
Similary, you can also use toCharArray().length
.
String name = "corejava" ;
System.out.println(name.toCharArray().length); // 8