I want to read a String character by character which is already in an array.
String ss = "makassar";
String my_array[] = ss.split("");
for (int i = 1; i < ss.length()+1; i++) {
if (my_array[i]=="m") {
Toast toast = Toast.makeText(this, "Array is M", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
// Toast not show
}
}
Toast is not getting displayed. Why? Any idea?
You should use
equals()and notoperator==to compare strings.operator==checks for identity of objects [if the left and the right are the same object], whileequals()checks equality [if the 2 strings equal each other].Change this:
to this:
Also, note that
my_array[1]is the second element, and not the first, so you might want to start fromi = 0and noti = 1