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
package foo; | |
import java.util.Arrays; | |
import java.util.Locale; | |
/** | |
* @author bruno borges | |
*/ | |
public class Foo { | |
public static void main(String[] args) { | |
final String formatOutput = "Country : %s \t\t\t\t:\t Country Code : %s"; | |
List<String> list = | |
Arrays.asList(Locale.getISOCountries()) | |
.stream() | |
.map(c -> new Locale("", c)) | |
.sorted((c0, c1) -> c0.getDisplayCountry().compareTo(c1.getDisplayCountry())) | |
.map(l -> String.format(formatOutput, l.getDisplayCountry(), l.getCountry())) | |
.collect(Collectors.toList()); | |
list.forEach(System.out::println); | |
} | |
} |
And if you want to collect all that to a list instead of printing to standard output, replace the last forEach call with collect(Collectors.toList()); and assign a variable.
Nenhum comentário:
Postar um comentário