Skip to content

Instantly share code, notes, and snippets.

@liviutudor liviutudor/
Last active Apr 1, 2017

What would you like to do?
Find max int in a collection in java without using streams
public Integer max(Collection<Integer> collection) {
if( collection == null || collection.isEmpty() ) return null;
Iterator<Integer> i = collection.iterator();
int max =;
while (i.hasNext()) {
int n =;
if (max < n) max = n;
return max;
List<Integer> list = ...;
Integer m = max(list);
int maximum = (m == null) ? 0 : m.intVal();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.