Hard
This code
SimpleDateFormat format = new SimpleDateFormat("DD");
ExecutorService executor = Executors
.newFixedThreadPool(10);
Set<Future<String>> days = Collections
.newSetFromMap(new ConcurrentHashMap<>());
IntStream.range(1, 32)
.forEach(day -> {
Future<String> result = executor.submit(() -> {
Date date = new GregorianCalendar(2021,
Calendar.JANUARY, day).getTime();
return format.format(date);
});
days.add(result);
});
Set<String> results = days.stream()
.map(return result -> {
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError(e);
}
})
.collect(Collectors.toSet());
Author: Clément DevosStatus: PublishedQuestion passed 345 times
Edit
4
Community EvaluationsNo one has reviewed this question yet, be the first!
Similar QuestionsMore questions about Java
2
Write a function that returns the first character of a string in Java1
Java code that replaces keys in a template with their values.1
A Java class that converts Arabic numbers to Roman numerals.1
Write a Java implementation of the FizzBuzz code kata.1
A code kata is a small exercice thought to train a certain development competence