How do I search an array of objects by attribute (Java) -


Is it possible to find an array of objects in Java with the Private attribute with Array.binarySearch method? I was thinking that there should be something similar to sorting techniques, where you create a class that operates the compressor and pass it in the array, but I can not find anything (maybe something that is comparable Instead of the method you only return the attribute used in the search) ??

To be clear, I have an array of anonymous station objects, and it is passed to another class, where I want to find an array for the name of the stations, which is a getName () Can be backed by.

Any help would be greatly appreciated!

Yes - actually uses it comparator , which you have answered Specified!

If you keep an eye on the implementation of the binary search method in the API, then you come to it:

of the binary search algorithm Uses the search for the specified array for the specified object.

You can apply the comparator, and you can use it to do this. Private questions have been compared to your question.

Edit the feedback on the comment: T is one, which means that anything can happen, Every situation looks like this for so long. In this case, this means that the first parameter should be an array of the second parameter type. Or in other words, if you are adjusting T s ( station s in your case), then you will see that class ( station here To act as the object, this key argument will always be passed as one of the arguments of the comparator comparison method.

So I doubt you in the case that you were passing in the string representing the name of the station; You should instead go in an example of station , which has the proper name.


Comments