Java Articles

Page 132 of 450

How to use the collect() method in Stream API in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 2K+ Views

In this article, we will learn to use the collect() method in the Stream API in Java 9. Java Stream API collect() Method In Java, the collect() method in the Stream API collects all objects from a stream object and stores them in a type of collection. The user has to provide what type of collection the results can be stored. We specify the collection type using the Collectors Enum. There are different types, and different operations can be present in the Collectors Enum. Syntax The following is the syntax for the collect() method declaration: R collect(Collector

Read More

Difference between EnumMap and HashMap in Java

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 1K+ Views

In this article, we will learn about the EnumMap and HashMap in Java. First, we will know about EnumMap, the syntax of EnumMap, and an example after that will learn about HashMap, the syntax of HashMap, and an example. At the end, we will see a table showing the difference between EnumMap and HashMap. What is EnumMap? EnumMap is introduced in JDK 5. It is designed to use an Enum as a key in the Map. It is an implementation of the Map interface. All of the keys in the EnumMap should be of the same enum type. Keys cannot be ...

Read More

What is Unified JVM Logging in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 625 Views

In this article, we will learn about the unified JVM logging in Java 9. Logging in the JVM is a great tool for performing root cause analysis, and it is a part of the JDK(Java Development Kit). Starting from JDK 9, the JVM maintainers chose to rebuild the way the JVM logs things. What is Unified JVM Logging? Java 9 can provide a common logging system for JVM components with a detailed level. By using a new command-line option: -Xlog for all logging settings, and unified JVM logging, gives us an easy-to-configure tool to do a root cause analysis (RCA) ...

Read More

How to access each stack element of StackWalker in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 299 Views

In this article, we will learn to access each stack element of StackWalker in Java 9. We will learn about the StackWalker API and its methods, and use of getStackTrace() method for accessing each stack element. StackWalker API StackWalker API allows easy filtering and lazy access to execute tasks within any method. It is an efficient API for obtaining stack trace information in Java 9. StackWalker API is an alternative to Thread.getStackTrace() or Throwable.getStackTrace() and SecurityManager.getClassContext(). This API targets a mechanism to traverse and materialize required stack frames, allowing efficient lazy access to additional stack frames when required. The following ...

Read More

What is the use of the toEpochSecond() method in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 1K+ Views

In this article, we will learn about the use of the toEpochSecond() method in Java 9. First, we will learn about the LocalDate class, its methods, then we will know about the Epoch Time and the toEpochSecond() method with its uses and example in Java. LocalDate Class The LocalDate class is a part of java.time package. LocalDate class represents a date without a time-zone in the ISO-8601 calendar system, such as 2020-10-14. This class represents a date in the format yyyy-MM-dd. The following are some of the common methods of the LocalDate Class getDayOfMonth(): This ...

Read More

When to use the delayedExecutor() method of CompletableFuture in Java 9?

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jun-2025 4K+ Views

In this article, we will learn to use the delayedExecutor() method of CompletableFuture in Java 9. We're gonna know about the delayedExecutor() method and also the CompletableFuture class, as this method belongs to this class, and we're gonna know the uses of the delayedExecutor() method along with an example. CompletableFuture Class The CompletableFuture Class was introduced in Java 8. CompletableFuture is a class in java.util.concurrent package that implements the Future and CompletionStage Interface. CompletableFuture provides a powerful and flexible way to write asynchronous, non-blocking code. It supports delays and timeouts. The delayedExecutor() Method The delayedExecutor() method has been added ...

Read More

How do I insert all elements from one list into another in Java?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-Jun-2025 8K+ Views

In this article, we will learn how to insert all elements from one list into another in Java. This is a general operation we perform when working with lists while solving problems in Java. We will cover the following methods to insert all elements from one list into another: Using addAll() Method Using For Loop Using Stream API Using ListIterator Using addAll() Method We can add all elements of one list into another list easily using its addAll() method. This method appends all of the elements in the specified collection to the end of this list, in the ...

Read More

Can we insert null values in a Java list?

Aishwarya Naglot
Aishwarya Naglot
Updated on 13-Jun-2025 17K+ Views

Yes, we can insert null values into a list easily using its add() method. In case of List implementation does not support null, then it will thrown a NullPointerException List is an interface in Java that extends the Collection interface and provides a way to store an ordered collection of elements. It allows us to store duplicate elements, and it also maintains the order of insertion. The List interface is implemented by classes such as ArrayList, LinkedList, and Vector. Null Values in a Java List In Java, a List can contain null values. The List interface allows for the insertion of ...

Read More

How To Find Volume of the Octahedron in Java?

Vivek Verma
Vivek Verma
Updated on 13-Jun-2025 248 Views

An octahedron is a three-dimensional (3D) shape which has eight plane faces. In other words, a polyhedron is called an octahedron which has eight faces, twelve edges, and 6 vertices. A polygonal is a three-dimensional figure with flat polygonal faces, straight edges, and sharp corners or vertices. The word octahedron is derived from the Greek word that is Oktaedron, which means Eight faces. Here is the diagram of the octahedron, which has side a: Volume of octahedron The volume of an octahedron is the amount of space occupied by the octahedron. To calculate the volume of an octahedron, we ...

Read More

How To Check Whether a Number is a Keith Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 13-Jun-2025 3K+ Views

What is Keith Number? A number is said to be a Keith number if it is arranged with a special sequence of numbers, which are initially created by its digits. The number sequence will be generated by adding its previous numbers till the number exceeds the input number. The results will be decided if the end number is exactly the same as the input number. For example, let's consider the number 14. The sequence will be as follows: s1 = 1, 4 s2 = 1, 4, 1 + 4 s3 = 1, 4, 5, 4 + 5 s4 = ...

Read More
Showing 1311–1320 of 4,498 articles
« Prev 1 130 131 132 133 134 450 Next »
Advertisements