In my experience, most large projects will have some files for "common" functions, which are usually all kinds of helper functions like this one that don't have a built-in language library.
In your case, I would create a new folder (a new package for Java) called "General", and then create a file to group functions (for Java, it will be just a class with a lot of static elements).
For example, in your case, I would have something like: General / ArrayUtils.java, and in this I would throw your function and any other function that you need.
Do not worry that at the moment this makes the new class (and package) only for one function. As you said in the question, this will be what you will use for the next project, and the next. Over time, this “General” package will begin to grow with all sorts of really cool helper classes, such as MathUtils, StringUtils, etc., which you can easily copy for every project you are working on.
Edan maor
source share