Which of the following options is considered a good practice to loop through the String
?
Should we use charAt
or convert to a char array ? I am looking for answers in all terms including performance and space used
public static void doChose (String str) {
for (int i = 0; i < str.length(); i++) {
System.out.println(str.charAt(i));
}
// vs
char[] chars = str.toCharArray();
for (char c : chars) {
System.out.println(c);
}
}