java-8 Questions
11
Solved
I have code which implements a "lock handler" for arbitrary keys. Given a key, it ensures that only one thread at a time can process that(or equals) key (which here means calling the externalSystem...
Boony asked 27/1, 2017 at 16:13
4
Solved
Suppose we have two streams as follows:
IntStream stream1 = Arrays.stream(new int[] {13, 1, 3, 5, 7, 9});
IntStream stream2 = Arrays.stream(new int[] {1, 2, 6, 14, 8, 10, 12});
stream1.merge(stream...
Selfish asked 30/9, 2018 at 4:0
5
Solved
So after some reading I've seen that
if (optional.isPresent()) {
//do smth
}
is not the preferred way to use Optional (http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.ht...
Wellchosen asked 20/1, 2016 at 14:5
7
Solved
How do I sort string values in case-insensitive order in the following?
List<Employee> listofEmployees = Arrays.asList(
new Employee(1, "aaa", Arrays.asList(123, 345, 678)),
new Employee(1...
Permeate asked 13/4, 2018 at 16:50
10
I have just installed Java SE Development Kit 8u91 on my 64 bit Windows-10 OS. I set my path variables . I tried java --version in my command prompt it gave me an error.
c:\Users\Onlymanu>java ...
4
Solved
Currenty, I am unable to resolve the crash that is java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Instant; Such crash happens with Android 7.1.1 (Nougat) and below. But my Oreo em...
12
Solved
How to implement "partition" operation on Java 8 Stream? By partition I mean, divide a stream into sub-streams of a given size. Somehow it will be identical to Guava Iterators.partition()...
Careen asked 7/9, 2015 at 8:50
6
Solved
As you hopefully know you can use lambdas in Java 8, for example to replace anonymous methods.
An example can be seen here of Java 7 vs Java 8:
Runnable runnable = new Runnable() {
@Override
pu...
Gape asked 13/3, 2014 at 12:18
3
Solved
Why are static methods supported from Java 8? What is the difference between the two lines in main method in below code?
package sample;
public class A {
public static void doSomething()
{
Syst...
Bal asked 20/8, 2017 at 10:7
10
Solved
Suppose I have a method that returns a read-only view into a member list:
class Team {
private List<Player> players = new ArrayList<>();
// ...
public List<Player> getPlayers...
Eberhardt asked 10/7, 2014 at 12:42
5
Solved
I have a Stream<Set<Integer>> intSetStream.
I can do this on it...
Set<Integer> theSetWithTheMax = intSetStream.max( (x,y)->{ return Integer.compare( x.size(), y.size() ); } ...
Mommy asked 11/4, 2018 at 19:6
4
Solved
I am getting
Cannot infer type arguments for java.util.HashMap<>
for the following code
class Test {
public static void main(String[] args) {
Map<Integer, String> map = new Ha...
Algebraist asked 23/11, 2017 at 7:17
2
Solved
According to the system requirements, even Java 7 requires Lion, but then I found this question: How to install java jdk 7 on Snow Leopard. Especially the answer stating that java 7 doesn't, in fac...
Mchugh asked 28/7, 2014 at 12:15
2
Solved
I have a list of orders and I want to group them by user using Java 8 stream and Collectors.groupingBy:
orderList.stream().collect(Collectors.groupingBy(order -> order.getUser())
This return ...
Rundlet asked 14/6, 2016 at 14:57
14
Solved
I have this list (List<String>):
["a", "b", null, "c", null, "d", "e"]
And I'd like something like this:
[["a", "b"], ["c"], ["d", "e"]]
In other words I want to split my list in sublis...
Electronegative asked 17/3, 2015 at 9:52
35
Solved
In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object?
For example I have a list of Person object and I want to remove people with ...
Amaris asked 16/5, 2014 at 15:40
7
Solved
Is it possible to cast a stream in Java 8? Say I have a list of objects, I can do something like this to filter out all the additional objects:
Stream.of(objects).filter(c -> c instanceof Clien...
Contrite asked 19/3, 2014 at 16:9
6
I have a List of Integer say list1, and I want to get another list list2 which will contain the cumulative sum up until the current index from start. How can I do this using Stream API java 8 ?
Li...
Nardone asked 20/3, 2019 at 16:32
4
I have a problem which I feel would be perfect for streams and/or lambdas. On the other hand I don't want to overcomplicate this, but since will use this specific technique in many variations (run ...
Cutch asked 3/4, 2017 at 19:2
8
Solved
What is the recommended way to transform a stream into a sliding window?
For instance, in Ruby you could use each_cons:
irb(main):020:0> [1,2,3,4].each_cons(2) { |x| puts x.inspect }
[1, 2]
[2, ...
Alansen asked 8/12, 2015 at 14:38
23
Solved
Given an object or primitive stream such as { 0, 1, 2, 3, 4 }, how can I most elegantly transform it into given form (assuming, of course, I've defined class Pair)?
{ new Pair(0, 1), new Pair(1, 2)...
Caldera asked 9/12, 2013 at 11:55
4
Solved
I have a Map<String, List<String>>. I want to transform this map to a List after filtering on the map's key.
Example:
Map<String, List<String>> words = new HashMap<>...
Lees asked 18/7, 2017 at 21:13
3
Solved
I found a new and undocumented javadoc tag at LongStream class documentation. The javadoc tag @apiNote seems to be used to detail some explanation about a method, but there's no documentation or re...
5
Solved
For the following Period calculation:
Period.between(LocalDate.of(2015, 8, 1), LocalDate.of(2015, 9, 2))
the result is:
P1M1D
This is equivalent to 31 days + 1 day = 32 days.
For this Period...
12
Solved
I came across a new term in Java 8: "functional interface". I could only find one use of it while working with lambda expressions.
Java 8 provides some built-in functional interfaces and ...
Jurisprudent asked 27/4, 2016 at 6:21
© 2022 - 2024 — McMap. All rights reserved.