Created
April 30, 2015 01:50
-
-
Save lucascs/4da0b492c496dc32e745 to your computer and use it in GitHub Desktop.
Capitalize java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
vlw man, estava precisando hehehehe nada melhor que uma boa googlada pra achar essas paradas prontas... ;)