sorting collections with comparator java
Collections.sort(marvel, new Comparator<String>() {
@Override
public int compare(String hero1, String hero2) {
return hero1.compareTo(hero2);
}
});
sorting collections with comparator java
Collections.sort(marvel, new Comparator<String>() {
@Override
public int compare(String hero1, String hero2) {
return hero1.compareTo(hero2);
}
});
sorting collections with comparator java
public class MarvelComparator {
public static void main(String... comparator) {
List<String> marvelHeroes = new ArrayList<>();
marvelHeroes.add("SpiderMan ");
marvelHeroes.add("Wolverine ");
marvelHeroes.add("Xavier ");
marvelHeroes.add("Cyclops ");
Collections.sort(marvelHeroes, new Comparator<String>() {
@Override
public int compare(String hero1, String hero2) {
return hero1.compareTo(hero2);
}
});
Collections.sort(marvelHeroes, (m1, m2) -> m1.compareTo(m2));
Collections.sort(marvelHeroes, Comparator.naturalOrder());
marvelHeroes.forEach(System.out::print);
}
}
sorting collections with comparator java
Collections.sort(marvel, new Comparator<String>() {
@Override
public int compare(String hero1, String hero2) {
return hero1.compareTo(hero2);
}
});
sorting collections with comparator java
public class MarvelComparator {
public static void main(String... comparator) {
List<String> marvelHeroes = new ArrayList<>();
marvelHeroes.add("SpiderMan ");
marvelHeroes.add("Wolverine ");
marvelHeroes.add("Xavier ");
marvelHeroes.add("Cyclops ");
Collections.sort(marvelHeroes, new Comparator<String>() {
@Override
public int compare(String hero1, String hero2) {
return hero1.compareTo(hero2);
}
});
Collections.sort(marvelHeroes, (m1, m2) -> m1.compareTo(m2));
Collections.sort(marvelHeroes, Comparator.naturalOrder());
marvelHeroes.forEach(System.out::print);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us