Guest User

Untitled

a guest
Dec 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. private static String summarizeLastWords(List<String> descriptions) {
  2. StringBuffer output = new StringBuffer();
  3. boolean isFirst = true;
  4. for (String d: descriptions) { // External Iteration
  5. if (!d.isEmpty()) {
  6. if (!isFirst) {
  7. output.append(" & ");
  8. }
  9. String lastWord = lastWord(d);
  10. output.append(lastWord);
  11. isFirst = false;
  12. }
  13. }
  14. return output.toString();
  15. }
  16.  
  17. private static String lastWord(final String d) {
  18. final int lastSpaceIndex = d.lastIndexOf(" ");
  19. final String lastWord;
  20. if (lastSpaceIndex < 0) {
  21. lastWord = d;
  22. } else {
  23. lastWord = d.substring(lastSpaceIndex + 1, d.length());
  24. }
  25. return lastWord;
  26. }
Add Comment
Please, Sign In to add comment