I have an array:
char[] modifiers = {'A', 'M', 'D'};
and a variable:
char a = 'D'
How to get position of variable value in array?
Thanks
This is the shortest way I know. I had this as a comment but now writing it as an answer. Cheers!
Character[] array = {'A','B','D'};
Arrays.asList(array).indexOf('D');
Something along the lines may do the trick:
Collections.indexOfSubList(Arrays.asList(array), Arrays.asList('D'))
Trying to avoid a manual loop :p
You could do it yourself easily enough, you can use the sort() and binarySearch() methods of the java.util.Arrays class, or you can convert the char [] to a String and use the String.indexOf() method.
new String(modifiers).indexOf('D') is a pretty concise way to do this.