HTML

How to remove duplicates from Stream in Java 8 - Stream.distinct() Example

You can use the Stream.distinct() method to remove duplicates from a Stream in Java 8 and beyond. The distinct() method behaves like distinct clause of SQL which removes duplicate rows from the result set. The distinct() is also an intermediate method which means it will return a new Stream without duplicates, which can be used for further processing. Like other methods of Stream class e.g. map() or filter(), distinct() is also lazy and it will not remove duplicate elements until you call a terminal method on Stream.  The actual processing of Stream pipeline starts only after calling terminal methods like collect() or forEach().

Top 5 Spring Cloud Annotations for Java Developers

If you are developing Java application for Cloud then you should learn Spring Cloud, a great framework and extension of popular Spring framework which can help you to develop a cloud-native Java application. Spring Cloud provides several necessary services required for a cloud-based Java application like configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, a control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state etc. On top of that, it builds on the Spring framework so it automatically provides the essential features like dependency injection and inversion of control, which results in loosely coupled and easy to test Java application.

How to convert int[] to ArrayList in Java 8? Example Tutorial

I once asked this question to one of the Java developers during Interview and like many other, he answered that Arrays.asList() can convert an array of primitive integer values to ArrayList<Integer> in Java, which was actually wrong. Even though, Arrays.asList() is the go-to method to convert an array to ArrayList in Java when it comes to converting a primitive array to ArrayList, this method is not useful. The Arrays.asList() method does not deal with boxing and it will just create a List<int[]> which is not what you want. In fact, there was no shortcut to convert an int[] to ArrayList<Integer> or long[] to ArrayList<Long> till Java 8.