One of the common programming exercise on various Java course is addition and multiplication of two arrays. How do you add two integer arrays in Java? Can you add two String array? how about other data types etc? These are some of the interesting questions because Java doesn't support operator overloading. You cannot use the plus operator to add two arrays in Java e.g. if you have two int arrays a1 and a2, doing a3 = a1 + a2 will give compile time error. The only way to add two arrays in Java is to iterate over them and add individual elements and store them into a new array. This is also not easy because the array can be of different length, so you need to make some rules and apply them to your method e.g. you can throw IllegalArgumentException if you get two arrays which are not of the same type and their length is different.
Read more »