I'm making a class that uses an ArrayList as a data member. I want everything to be consistent in the class; so, I used Integer instead of int in the entire class and in everywhere.
For example these functions:
public Integer getMax();
public void sort(Integer n);
My question: is this better than using int? Can someone define the following: ?
int i = obj.getMax();
// or this:
int size = 0;
obj.sort(size);
I know that Integer is an object type whereas int is a primitive type. However, I don't really know the difference in usage in such cases!
When is it better to use Integer and when is it better to use int?
maxandsortI suggest you look at how this is done in Java 8.maxreturns an Optional which is considered better practice than returningnull