Created
April 7, 2014 15:32
-
-
Save archena/10022529 to your computer and use it in GitHub Desktop.
Iterators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean r = isOrdered(Arrays.asList(1, 3, 5, 7)); // true | |
boolean r2 = isOrdered(Arrays.asList(1, 5, 5, 7)); // false | |
boolean r3 = isOrdered(Arrays.asList(5, 3, 6, 7)); // false | |
public static <T extends Comparable<T>> boolean isOrdered(Collection<T> collection) { | |
final Iterator<T> i = collection.iterator(); | |
final Iterator<T> j = collection.iterator(); | |
j.next(); | |
while(j.hasNext()) | |
if(i.next().compareTo(j.next()) >= 0) | |
return false; | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment