Chen, how does this explain that the propopsal "is not good"?
It is not on us to decide what others do with the tools we provide, as long as we DO provide them. IF people are using primitive arrays, and IF they need to search them in an UNSORTED fashion, Arnav's proposed API would allows us to apply vectorization. Hence, the result COULD be multiple times faster than custom search loops. As long as primitive arrays DO exist, I would rather say, his proposal "is good".
-Markus Am 06.04.2026 um 02:40 schrieb Chen Liang:
Hello, I don't think this is a good proposal. Nowadays, primitive arrays are used as an efficient storage format, much more compact than reference arrays. However, they all suffer from the mutability issue as all the arrays: when you pass arrays across trust boundaries, you should always sanitize the input arrays and output arrays. In this sanitization process, we usually can convert these arrays to more efficient formats, such as performing a Arrays.sort call, and the subsequent search can be a Arrays.binarySearch(a, key) >= 0 call. Regards, Chen Liang ________________________________ From: Arnav Somaghatta <[email protected]> Sent: Sunday, April 5, 2026 9:58 AM To: [email protected] <[email protected]> Subject: [External] : Proposal for primitive arrays Hello, My name is Arnav, and I am a 14-year-old developer who is interested in contributing to the OpenJDK. I would like to propose adding a set of "contains" methods to the java.util.Arrays class. Currently, to check if a primitive array (like char or int) contains a specific value needs a large manual for loop, converting to a List, or using a very complicated Stream pipeline. My idea proposes adding a series of static "contains" methods for all 8 primitive types to java.util.Arrays public static boolean contains(char[] a, char key) public static boolean contains(int[] a, int key) public static boolean contains(byte[] a, byte key) public static boolean contains(short[] a, short key) public static boolean contains(long[] a, long key) public static boolean contains(float[] a, float key) public static boolean contains(double[] a, double key) public static boolean contains(boolean[] a, boolean key) Why should you consider this proposal? Arrays.contains(myChars, 'a') is much more readable than workarounds like a for loop. For newer Java learners, not having a "contains" method on arrays is very confusing when you compare it to other languages like Python. If this proposal is viewed favorably, I am willing to make all of the 8 primitive overloads and any of the corresponding unit tests. I am also looking for a sponsor to help me navigate the OCA process for minors and guide me through the technical process of pushing these changes. I look forward to your feedback on whether this is a direction the Core Libs group would support. Thank you so much for considering my idea and reading through this email, your support means a lot to me! Thank you, Arnav
