Ivan Franko wrote:I must return Exception? Which one?
This is the easiest, and the usual one is IllegalArgumentException.
I must return null?
Definitely not. Return
new ArrayList<Integer>(0) before a null.
I must return List with size 5000?
Reasonable; perhaps along with a message that tells the user they're a duffus.
What ways are the best?
There is no "best". It depends entirely on what your requirements are.
Winston