Let’s say I got this array:
String[][]array = new String[5][5];
array[2][2] = desperate;
Would it be possible to find whether
String s = “desperate”; – equals any array element without using a for loop, and without having to manually enter the row column combination of the array assigned the value “desperate”?
Use enhanced-for loop: –
Output: – desperate == desperate
A better way that I would suggest is to use
ArrayList<String>to store your items.. Then you can just callcontains()method to check whether the list contains that element..Output: – True