Sorry for the title maybe this may seem like a dummy question. I'm new in java and assume I have a char
array like this:
char[] hex = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
Now I want to find an item's index on that array for example 'a'
, but after some research I realized java's array class doesn't have an indexOf
method. So I did the following:
int index = new String(hex).indexOf('a');
And it works fine, and after that I try following code:
int index2 = Arrays.asList(hex).indexOf('a');
It doesn't work and after I saw this question I understood the reason. But now I'm curious why finding an index needs too much effort in Java and why we can't get index directly? Why java's Array
class doesn't have an indexOf
method? Or is there an other simple way to do this and I'm missing it?