I was wondering if I could compare the String Array value to a String, for eg; I have a String array which has 5 values on it. String [] sampleArray = {"a","b","a","b","a"} and I want to know which index value has a or b. I thought of an idea but it didn't work.
String[] sampleArray = {"a","b","a","b","a"};
String value;
for (int i=0; i <= sampleArray.length; i++){
if ( sampleArray[i].equals("a") ) {
value = "apple";
} else {
value = "ball";
}
System.out.println(value);
}
Basically if the index 0 is a then it should print "Apple" and if it's b it should print "ball" and so on. Is there any idea to compare values or string array to a string?
Stringarray which has 5 values on it.String [] sampleArray = {"a","b","a","b","a"}and I want to know if my first index value is whether a or b." if (sampleArray[0].equals("a"))` does that. What's the loop for?