Skip to content

Instantly share code, notes, and snippets.

@fabriciofx
Forked from lucascs/Capitalize.java
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save fabriciofx/fcf5fea1a39aa07e2e29 to your computer and use it in GitHub Desktop.

Select an option

Save fabriciofx/fcf5fea1a39aa07e2e29 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class Capitalize {
public static String capitalize (String x) {
return x.substring(0,1).toUpperCase() + x.substring(1).toLowerCase();
}
public static void main(String[] args) {
String text = "gabinete do deputado fulando de tal e de dona maria";
String capitalized =
Arrays.asList(text.split(" "))
.stream()
.map(x -> x.length() > 2 ? capitalize(x) : x)
.reduce((x,y) -> x + " " + y)
.orElse("");
System.out.println(capitalized); // => Gabinete do Deputado Fulando de Tal e de Dona Maria
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment