Skip to content

Instantly share code, notes, and snippets.

@akshaymittal143
Created October 6, 2018 19:47
Show Gist options
  • Save akshaymittal143/3fa5b40fd78c87eb0b16b9e3c63cff4a to your computer and use it in GitHub Desktop.
Save akshaymittal143/3fa5b40fd78c87eb0b16b9e3c63cff4a to your computer and use it in GitHub Desktop.
static String longestEvenWord(String sentence) {
//splitting words by space
String words[] = sentence.split(" ");
//sorting descending
Arrays.sort(words, (b, a)->Integer.compare(a.length(), b.length()));
for(String word: words) {
if(word.length() % 2 == 0) {
return word;
} else return "00";
}
return "00";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment