Traverse the characters in a string

Java traverses every letter of a string

String str = "asdfghjkl";

method 1:

for(int i=0;i<str.length();i++){char ch = string.charAt(i);}

Method 2:

char[] c=s.toCharArray();for(char cc:c){...//cc直接用了}

Method 3:

for(int i=0;i<str.length();i++){String subStr = str.substring(i, i+1)}
Published 8 original articles · Likes2 · Visits 491

Guess you like

Origin blog.csdn.net/qq_42003546/article/details/102703405