Collections Class methods and its usages

import java.util.*; public class Main {public static void main(String[] args) {// sort(List list)List numbers = new ArrayList<>(Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5));Collections.sort(numbers);System.out.println("Sorted list: " + numbers); // reverse(List<T> list) List<String> names = new ArrayList<>(Arrays.asList("Alice", "Bob", "Charlie", "David")); Collections.reverse(names); System.out.println("Reversed list: " + names); // shuffle(List<?> list) List<Integer> shuffledNumbers = new ArrayList<>(Arrays.asList(1, 2,... Continue Reading →

Interview questions you must go through before java interview

How to move all 0s to the beginning and all 1s to the end of an array? Why is the main method in Java static? How do classes load in Java? What is the classpath and how does it differ from the system PATH? How many types of class loaders are there in Java? How... Continue Reading →

how ValueOf() can be used in java

The `valueOf()` method is a static method defined in several classes in Java, including `String`, `Integer`, `Double`, and others. It is used to convert a value of a specific type to an object representation of that type. The return type of the `valueOf()` method is typically the corresponding class itself. Here are a few examples... Continue Reading →

Use of break , Continue in java

public class Test { public static void main(String[] args) { singleLoop: for (int i = 1; i <= 5; i++) { if (i == 3) { break singleLoop; // Exit the loop when i equals 3 } System.out.println(i); } } } Above is the use of break into labelled loop. labelled loops can be used... Continue Reading →

Stream api methods with examples

Certainly! Here are the examples of each method in the Stream API without using method references: 1. `filter(Predicate<T> predicate)`: ```java List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); List<Integer> evenNumbers = numbers.stream() .filter(n -> n % 2 == 0) .collect(Collectors.toList()); System.out.println(evenNumbers); // Output: [2, 4, 6, 8, 10] ``` 2.... Continue Reading →

Blog at WordPress.com.

Up ↑