There are several methods.., one method is by using toCharArray() method
package com.simplePrograms;
public class Length {
public static void main(String[] args) {
String blah = "HellO";
int count = 0;
for (char c : blah.toCharArray()) {
count++;
}
System.out.println("blah's length: " + count);
}
}
package com.simplePrograms;
public class Length {
public static void main(String[] args) {
String blah = "HellO";
int count = 0;
for (char c : blah.toCharArray()) {
count++;
}
System.out.println("blah's length: " + count);
}
}
0 comments:
Post a Comment