Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String summarizeLastWords(List<String> descriptions) {
- StringBuffer output = new StringBuffer();
- boolean isFirst = true;
- for (String d: descriptions) { // External Iteration
- if (!d.isEmpty()) {
- if (!isFirst) {
- output.append(" & ");
- }
- String lastWord = lastWord(d);
- output.append(lastWord);
- isFirst = false;
- }
- }
- return output.toString();
- }
- private static String lastWord(final String d) {
- final int lastSpaceIndex = d.lastIndexOf(" ");
- final String lastWord;
- if (lastSpaceIndex < 0) {
- lastWord = d;
- } else {
- lastWord = d.substring(lastSpaceIndex + 1, d.length());
- }
- return lastWord;
- }
Add Comment
Please, Sign In to add comment