
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 7442 Articles for Java

2K+ Views
NumberFormat helps you to format and parse numbers for any locale. It is the abstract base class for all number formats.Following are some of the methods of the NumberFormat class−Modifier and TypeMethod and DescriptionObjectclone()Overrides Cloneable.booleanequals(Object obj)Overrides equals.String.format(double number)Specialization of format.abstract StringBufferformat(double number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.Stringformat(long number)Specialization of format.abstract StringBufferformat(long number, StringBuffer toAppendTo, FieldPosition pos)Specialization of format.ExampleLet us now see an example to implement the NumberFormat class − Live Demoimport java.text.NumberFormat; import java.util.Locale; public class Demo { public static void main(String[] args) { NumberFormat n = NumberFormat.getCurrencyInstance(Locale.FRANCE); double points = 2.15; ... Read More

168 Views
The Byte class wraps a value of primitive type byte in an object.Following are the fields for Byte class−static byte MAX_VALUE − This is constant holding the maximum value a byte can have, 27-1.static byte MIN_VALUE − This is constant holding the minimum value a byte can have, -27.static int SIZE − This is the number of bits used to represent a byte value in two's complement binary form.static Class TYPE − This is the Class instance representing the primitive type byte.ExampleLet us now see an example − Live Demoimport java.lang.*; public class Demo { public static void main(String[] args){ ... Read More

942 Views
The Byte class wraps a value of primitive type byte in an object. An object of type Byte contains a single field whose type is byte.Following are some of the methods of the Byte class −Sr.No.Method & Description1byte byteValue()This method returns the value of this Byte as a byte.2int compareTo(Byte anotherByte)This method compares two Byte objects numerically.3static Byte decode(String nm)This method decodes a String into a Byte.4double doubleValue()This method returns the value of this Byte as a double.5boolean equals(Object obj)This method compares this object to the specified object.6float floatValue()This method returns the value of this Byte as a float.7int hashCode()This ... Read More

4K+ Views
In this problem we are given an array of numbers, and we have to find the largest, smallest, second largest, and second smallest elements in an array in Java. Let’s understand the problem better with the help of an example: Input int arr[] = {55, 10, 8, 90, 43, 87, 95, 25, 50, 12}; Output Smallest element = 8 2nd Smallest element = 10 Largest element = 95 2nd Largest element = 90 To solve this problem, use the following approaches: Using Arrays.sort() Using nested for-loops Optimized one-pass approach Using Arrays.sort() In this ... Read More

1K+ Views
Given a list of numbers, our task is to calculate the average of this list. The average of a list can be found by adding all the elements in the list and dividing the sum by the total number of elements. In this article we will learn different methods to implement this in Java. There are multiple ways in Java to find the average of a list. In this article we will explore two different approaches: Using Java Streams Using for loop Find Average of a List Using Java Streams This approach shows how to find ... Read More

7K+ Views
A Supplier interface is a pre-defined interface that represents the supplier of results. It is instantiated using lambda expression or method reference or default constructor. The functional method of a Supplier interface is the get() method. This interface belongs to java.util.function package.Syntax@FunctionalInterface public interface SupplierIn the below program, we can use the Supplier interface in a lambda expression. The get() method only returns a value and doesn't accept any argument, so a lambda expression having an empty argument part.Exampleimport java.util.*; import java.util.function.*; public class SupplierTest { public static void main(String args[]) { Supplier supplier1 = () -> "TutorialsPoint"; // lambda expression System.out.println(supplier1.get()); ... Read More

2K+ Views
A Predicate interface defined in java.util.function package. It represents a boolean-valued function with one argument. It is kind of a functional interface whose functional method is the test(). BiPredicate interface is similar to the Predicate interface with two arguments. It can be used as an assignment target for a lambda expression.Syntax for Predicate@FunctionalInterface public interface PredicateExampleimport java.util.*; import java.util.function.*; import java.util.stream.*; public class EmployeePredicateTest { public static void main(String[] args) { Employee e1 = new Employee(1, 23, "M", "Raja"); Employee e2 = new Employee(2, 13, "M", "Jai"); Employee e3 = new Employee(3, 36, "F", "Yamini"); ... Read More

837 Views
Comparator interface can be used to order the objects of user-defined classes. It is capable of comparing two objects of two different classes. We can sort a list of objects where we can't modify the object’s source code to implement Comparable interface. A lambda expression can't be executed on its own and used to implement methods that are declared in a functional interface.In the below example, we need to sort a list by name using the Comparator interface and Stream API with the help of lambda expressions.Exampleimport java.util.*; import java.util.function.*; import java.util.stream.*; public class ListSortByNameTest { public static void main(String[] args) { List arrayList = new ArrayList(); ... Read More

2K+ Views
The Function interface is a pre-defined functional interface that can be used as an assignment target for a lambda expression or method reference. It takes a single parameter and returns result by calling the apply() method. While the BiFunction interface is also a pre-defined functional interface that takes two parameters and returns a result. It is similar to the Function interface except it takes two parameters.Syntax@FunctionalInterface public interface Function @FunctionalInterface public interface BiFunctionExampleimport java.util.function.BiFunction; import java.util.function.Function; public class SampleFunctionBiFunctionTest { public static void main(String[] args) { Function printNumber = a -> a*10; System.out.println("The number is: "+ printNumber.apply(10)); ... Read More

4K+ Views
A Consumer interface is a predefined functional interface that can be used when creating lambda expressions or method references. This interface represents an operation that accepts a single input parameter and doesn't return anything. It contains only one method named accept(). The BiConsumer interface is similar to a Consumer interface and accepts two input parameters and doesn’t return anything.Syntax@FunctionalInterface public interface Consumer @FunctionalInterface public interface BiConsumerExampleimport java.util.*; import java.util.function.*; public class ConsumerBiConsumerTest { public static void main(String[] args) { Consumer c = (x) -> System.out.println(x.toLowerCase()); // lambda expression c.accept("Raja"); Consumer con = (x) -> { // ... Read More