- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4348 Articles for Java 8
544 Views
Shell sort is a sorting technique that is similar to insertion sort, wherein elements are sorted which are at far ends (either ends) of the array. This way, the interval size between the next and the second to last element reduces. This happens for all the elements in the array until the interval distance is reduced to 0.ExampleFollowing is an example for ShellSort in Java − Live Demopublic class Demo { int shell_sort(int my_arr[]) { int arr_len = my_arr.length; for (int gap = arr_len / 2; gap > 0; gap /= 2) { ... Read More
313 Views
As the name suggests, pigeon holes are created, where the number of pigeon holes created is calculated using ‘max-min+1’, which is also known as the range of the array elements. The elements in the original array are iterated over and placed in the pigeonholes based on a specific condition.Further, after all elements are put in the pigeonhole, they are put back into the array in the same order in which they were placed in the pigeon holes.ExampleFollowing is an example for Pigeonhole sort in Java − Live Demoimport java.lang.*; import java.util.*; public class Demo { public static void pigeonhole_sorting(int my_arr[], ... Read More
300 Views
Radix sort is a sorting technique that sorts the elements based on every digit in every element (or number). Based on the ones place digit (which is also known as least significant digit) and tens place digit (which is also known as most significant digit), hundreds place digit, and so on, the elements are sorted.ExampleFollowing is an example for Radix Sort in Java − Live Demoimport java.util.*; public class my_radix_sorting { static int get_max_val(int my_arr[], int arr_len) { int max_val = my_arr[0]; for (int i = 1; i < arr_len; i++) ... Read More
516 Views
Pancake sorting is a sorting technique that resembles selection sort, i.e. sorting the largest element first thereby reducing the size of the array and eventually sorting all the elements. In pancake sorting, the idea is to sort the array elements by making the least number of reversals.Following is an example for Pancake sorting in Java −Example Live Demoimport java.io.*; public class pancake_sorting { static void flip_array(int my_arr[], int i) { int temp, beg = 0; while (beg < i) { temp = my_arr[beg]; my_arr[beg] = my_arr[i]; ... Read More
64 Views
LongToDoubleFunction is a built-in functional interface and part of java.util.function package. This functional interface accepts a long-valued parameter as input and produces a double-valued result. LongToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().Syntax@FunctionalInterface interface LongToDoubleFunction { double applyAsDouble(long value); }Example of Lambda Exampleimport java.util.function.LongToDoubleFunction; public class LongToDoubleLambdaTest { public static void main(String args[]) { LongToDoubleFunction getDouble = longVal -> { // lambda expression double doubleVal = longVal; return doubleVal; }; long input = ... Read More
123 Views
LongToIntFunction is a functional interface from java.util.function package introduced in Java 8. This functional interface accepts a long-valued parameter as input and produces an int-valued result. LongToIntFunction interface can be used as an assignment target for a lambda expression or method reference. This interface contains only one abstract method: applyAsInt() and doesn't contain any default and abstract methods.Syntax@FunctionalInterface interface LongToIntFunction { int applyAsInt(long value); }Example of Lambda Expressionimport java.util.function.LongToIntFunction; public class LongToIntLambdaTest { public static void main(String args[]) { LongToIntFunction getInt = longVal -> { // lambda expression int intVal = (int)longVal; ... Read More
84 Views
IntToLongFunction is a built-in functional interface from java.util.function package. This functional interface accepts an int-valued parameter and produces a long-valued result. IntToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface IntToLongFunction { long applyAsLong(int value); }Example of Lambda Expressionimport java.util.function.IntToLongFunction; public class IntToLongFunctionLambdaTest { public static void main(String args[]) { IntToLongFunction getLong = intVal -> { // lambda expression long longVal = intVal; return longVal; }; int input = 40; ... Read More
123 Views
IntToDoubleFunction is a functional interface from java.util.function package. This functional interface accepts an int-valued argument and produces a double-valued result. IntToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().Syntax@FunctionalInterface interface IntToDoubleFunction { double applyAsDouble(int value); }Example of Lambda Expressionimport java.util.function.IntToDoubleFunction;; public class IntToDoubleLambdaTest { public static void main(String[] args) { IntToDoubleFunction getDouble = intVal -> { // lambda expression double doubleVal = intVal; return doubleVal; }; int input ... Read More
2K+ Views
A lambda expression is a function that expects and accepts input parameters and produces output results. It is an instance of a functional interface and also known as a single abstract method interface (SAM interface) like Runnable, Comparator, Callable and etc. We can declare a variable as a final string[] array and able to access that array index within a lambda expression.Exampleimport java.util.*; public class LambdaTest { public static void main(String args[]) { final String[] country = {null}; List cities = new ArrayList(); cities.add("Hyderabad"); cities.add("Ireland"); cities.add("Texas"); ... Read More
150 Views
DoubleToLongFunction is a built-in functional interface from java.util.function package introduced in Java 8. This functional interface accepts a double-valued parameter and produces a long-valued result. DoubleToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface public interface DoubleToLongFunction { long applyAsLong(double value) }Exampleimport java.util.function.DoubleToLongFunction; public class DoubleToLongFunctionTest { public static void main(String args[]) { double dbl = 30.1212; DoubleToLongFunction castToLong = (dblValue) -> (long) dblValue; // lambda expression System.out.println(castToLong.applyAsLong(dbl)); dbl = 77.9212; DoubleToLongFunction roundToLong = Math::round; ... Read More