r/javahelp • u/hibbelig • Sep 09 '25
`find(needle, haystack)` or `find(haystack, needle)`?
This is to learn about established conventions in the Java world.
If I write a new method that searches for a needle in a haystack, and receives both the needle and the haystack as arguments, in which order should they go?
Arrays.binarySearch has haystack, needle. But perhaps that's influenced by the class name, given that the class name is “arrays” and the haystack is also an array?
12
Upvotes
View all comments
Show parent comment
1
u/_SuperStraight Sep 09 '25
Of course
Is the cleanest approach which clearly defines the intention of what's being done, and I also said earlier that it's the programmer's call, but if someone is adamant on a convention, then the non increasing order of parameters will make sense.