I have a situation, where I have to apply a criteria on an input array and reuturn another array as output which will have smaller size based upon the filtering criteria.
You can't... an array's size is always fixed in Java. Typically instead of using an array, you'd use an implementation of List
here - usually ArrayList
, but with plenty of other alternatives available.
You can create an array from the list as a final step, of course - or just change the signature of the method to return a List
to start with.