in Education by
What is indexOf method in Java, I can't seem to find it anywhere. Also how do I use it? Select the correct answer from above options

1 Answer

0 votes
by
There is no indexof method in Java. There is Array.Indexof method in C# but java has no such method. The method of indexOf is defined in the java docs . Now, If our array is sorted, then it is easy, because the Arrays class defines a series of overloads of the binarySearch method that will find the index of the element, like shown below. java.util.Arrays.binarySearch(Array, o) But if the array is not sorted, then we have 2 further cases, If the array is not sorted and it is not array of primitives, then using Array utility class we can use the indexOf method defined in there. java.util.Arrays.asList(theArray).indexOf(o) If the array is not sorted and it array of primitives, then there is no help that you can get from java APIs and you will have to write it on your own, or check out Guava's Chars.indexOf, it lets you get the index in an array.

Related questions

0 votes
    I have bit a problem. I need insert to Array only (example) first array, best field by field. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    I have a map stored as a multidimensional array ($map[row][col]) and I'd wish to create a path from ... path inside these values? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Which of these classes is not part of Java's collection framework? (a) Maps (b) Array (c) Stack (d ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of this interface is not a part of Java's collection framework? (a) List (b) Set (c) SortedMap ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Which of these class object can be used to form a dynamic array? (a) ArrayList (b) Map (c) Vector ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these class object has an architecture similar to that of array? (a) Bitset (b) Map (c) ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    If the size of the array used to implement a circular queue is MAX_SIZE. How rear moves to traverse inorder ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these method of Array class is used sort an array or its subset? (a) binarysort() (b) ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which is better in terms of performance for iterating an array? (a) for(int i=0; i=0; i-) (c) ... Autoboxing & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
...