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 369 times
Edit
4
Community EvaluationsNo one has reviewed this question yet, be the first!
1
Write a Java implementation of the FizzBuzz code kata.1
What does SRP stand for?1
What is the name of the design pattern used to structure complex applications by considering the problem domain?1
A code kata is a small exercice thought to train a certain development competence1
Java code that replaces keys in a template with their values.1
A Java class that converts Arabic numbers to Roman numerals.2
Write a function that returns the first character of a string in Java