String word = "Modern Programming";
String find = "r";
int index = word.indexOf(find);
while (index >= 0) {
System.out.println(index);
index = word.indexOf(find, index + 1);
}
หรือ charAt()
Code (Java)
String word = "Modern Programming";
ArrayList<Integer> list = new ArrayList<Integer>();
char find = 'n';
for(int i = 0; i < word.length(); i++){
if(word.charAt(i) == find){
list.add(i);
}
}
for(Integer i : list){
System.out.println(i);
}