Unless there's some reason why to has to be an ArrayList, by declaring the variable as a List you allow the possibility of (eg) changing the implementation to a LinkedList sometime later, secure in the knowledge that you will not break any existing code.
ps: Exactly the same logic applies to defining the return type for a method.
If your method returns a collection of <X> in a particular order, just declare the method as returning a List and implement it internally however seems best at the time. Similarly, if it returns a collection in no particular order (but without duplicates) declare it as returning a Set.
^ again, yes. Or Set<Y extends X> where X is an interface. Lists implies order which may not be relevant or defined, so, for example, if you switch the implementation from a List to a Map (often happens) it's easy to return the keySet()
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...