-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
25 lines (21 loc) · 761 Bytes
/
Copy pathSolution.java
File metadata and controls
25 lines (21 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Arrays;
import java.util.Comparator;
class Solution
{
private static final Comparator<String> COMPARATOR = Comparator.comparing(String::length);
private static final String DELIMITER = " ";
public String arrangeWords(String text)
{
final String[] words = text.split(DELIMITER);
words[0] = words[0].toLowerCase();
Arrays.sort(words, COMPARATOR);
final StringBuilder result = new StringBuilder();
final String firstWord = Character.toUpperCase(words[0].charAt(0)) + words[0].substring(1);
result.append(firstWord);
for (int i = 1; i < words.length; i++)
{
result.append(DELIMITER).append(words[i]);
}
return result.toString();
}
}