everyone. I've faced a task, that looked pretty simple to me, but I spend like 4 hours and left with nothing. So, let's assume we have simple list of integers like [1, 2, 3, 4, 5] I want to get sum of subtractions for each element - for this list, it
How can i check if one range from numbers is divided by more than one number. For example if it is only 1 divisor this will work , but i don't know what to do when i have an array from numbers : int limitNumber = 10; int onlyOneDivisor = 2; String in
assuming I have the code like as below: Future<Object> executeBy(ExecutorService executor) { return executor.submit(() -> { throw new IllegalStateException(); }); } there is no problem when using ForkJoinPool#commonPool, but when I using a parall
So I have this code that "works" (replacing some names for simplicity): Map<String, Map<String, ImmutableList<SomeClassA>>> someMap = someListOfClassA.stream() .filter(...) .collect(Collectors.groupingBy(SomeClassA::someCriteri
How do you put multiple method calls (e.g 'get' in the below case) in a block? package Routes; import org.jooby.mvc.Path; public class UserRoutes extends BaseRoutes { { get("/users", (req, resp) -> { resp.send("Uses index"); }); get
We developed an API call which uses Java8 parallel streams and we have got very good performance, almost double compared to sequential processing when doing stress tests. I know it depends on the use case, but I am using it for crypto operations, so
I downloaded the android studio 2.4 preview 6. It has support for java 8 without using jack. This is my application gradle filebuildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.4.0-alpha6' // NOTE: Do
I have written an entity that contains just a LocalDateTime to a CSV file using Super CSV's ICsvDozerBeanWriter and I am encountering an error when reading it back using a ICsvDozerBeanReader. I was able to successfully read and write a Date object b
I am trying to run a Travis CI test. Like this: language: java jdk: oraclejdk8 sudo: false script: mvn test It should be really simple... but I get this erro: diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond
Using Jdk8. I am trying to convert time actually just hours of the day (like 1130) into DateTime. I am trying it 2 ways as below none of them work correctly. 1130 gets converted into 11:00 and another 3:00 none of them are correct. Is there also a 3r
Take a look at this piece of code. // group by price, uses 'mapping' to convert List<Item> to Set<String> Map<BigDecimal, Set<String>> result = items.stream().collect( Collectors.groupingBy(Item::getPrice, Collectors.mapping(Item::
I'm writing essentially a small calaculator where you input two numbers, an operand like "+, -, *, /" etc and it'll preform that function. My initial thoughts have been to just have the variables get entered by the user, than just have them comp
Trying to figure out how to get along with Java 8 Repeatable annotations support. Following : https://blog.idrsolutions.com/2015/03/java-8-repeating-annotation-explained-in-5-minutes/ it works flawlessly. But if I'm modifying the example and add just
I have an object like so public class Organization { private List<Employee> employees; public static class Employee { private String department; private String designation; } } I have a search method that takes in a Map<String, Object>. This m
Trying to build an alexa (amazon:echo) skills set. At the same time, trying to use this experience as a learning testbed for dependency injection through dagger 2. However, building the package using maven-2 cmd: mvn assembly:assembly -DdescriptorId=
I made a method with type arguments, returning a generic type using these type arguments, and taking Function arguments which also depends on the type arguments. When I use lambdas as arguments, the compiler forces me to specify the type arguments of
I was reading the API for the ZoneId class. It states that there are three tipes of ID: derived from ZoneOffset offset-style IDs with some form of prefix. Examples: ZoneId.of("GMT+2"); ZoneId.of("UTC"); ZoneId.of("UT+01:00");
I want to match a string that can be either KH1 or KH2 or ... KH99. I did, public class Test1 { public static void main(String[] args) { String name = "KH1"; if(name.matches("[[K][H][1-9][0-9]]") || name.matches("[[K][H][1-9]]&quo
I have an issue with matching some of punctuation characters when Pattern.UNICODE_CHARACTER_CLASS flag is enabled. For sample code is as follows: final Pattern p = Pattern.compile("\\p{Punct}",Pattern.UNICODE_CHARACTER_CLASS); final Matcher matc
My colleague and I had a bug that was due to our assumption that an empty stream calling allMatch() would return false. if (myItems.allMatch(i -> i.isValid()) { //do something } Of course, it is kind of our fault for assuming and not reading document
I have a Map<String, List<Object>> multiFieldMap and I need to itereate over its value set and add the value to multiFieldsList as below public List<Object> fetchMultiFieldsList() { List<Object> multiFieldsList = new ArrayList<O
I have created a single jar for Java 7 & 8 for a JDBC driver (using -source/-target compile options). However, I am having difficulty compiling applications that use the new/overloaded methods in the ResultSet interface: //New in Java 8 updateObject(
I can explain this one only with the example. We have the main class, AppServer. It holds also several application-wide components. AppServer app = new AppServer(config, ...); Now we need to provide a supplier that will act as a factory for some Foo
I'm starting to learn about Java 8 streams and lambdas expressions. I want to iterate a collection but I'm getting a compilation error. I understand why is happening this error but I don't know how to get rid of it. Below the code: List<TT021OrderDet
For example, if I intend to partition some elements, I could do something like: Stream.of("I", "Love", "Stack Overflow") .collect(Collectors.partitioningBy(s -> s.length() > 3)) .forEach((k, v) -> System.out.println(
While reading up on the new features introduced in Java 8, I came across the concept of Predicates. I noticed that most of the examples provided on the internet and in books use static functions to create predicates. Consider the following Apple clas
When I iterate over a collection using the new syntactic sugar of Java 8, such as myStream.forEach(item -> { // do something useful }); Isn't this equivalent to the 'old syntax' snippet below? myStream.forEach(new Consumer<Item>() { @Override pub
In Java 8, there is a new method String.chars() which returns a stream of ints (IntStream) that represent the character codes. I guess many people would expect a stream of chars here instead. What was the motivation to design the API this way?As othe
I am wondering if the following is possible with Java 8, for: Patch[][] patches = new Patch[width][depth]; I want to call the constructor using Streams, I know there is Arrays.stream(patches) which would give me a Stream<Patch[]>, so unfortunately I
I've been playing with CompletionStage/CompletableFuture in Java 8 in order to do asynchronous processing, which works quite well. However, sometimes I want a stage to perform asynchronous processing of an iterator/stream of items, and there doesn't