How to access the collection elements using the streams?

Streams is introduced in java8 version. It basically helps to write a concise piece of code and it’s functional style of code writing. For the complete piece of code please visit the below mentioned link. The piece of code for stream iteration is mentioned below :- In the above case the “forEach” is a terminal…

How to access collection elements in java using iterator method?

Iterator is a method which returns an iterator over elements. It is defined inside the “Iterable” interface of java collection framework. The source code of this interface can be found in the below mentioned link. Let’s create on collection of hotels as mentioned in the below mentioned code:- The source code of the “Hotel” class…

lambda examples in java language with code

Lambda expression is used for the implementation of the functional interfaces. Functional interface is those interfaces which has only one abstract method. We can declare an interface as functional interface by using the annotation @FunctionalInterface. e.g. Comparator interface in java is a functional interface. Please visit the official site for more information:- lambdaexpressions Example 1:-…

How many numbers are smaller than the current number

How many numbers are smaller than the current number:- Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j’s such that j != i and nums[j] < nums[i]. Return the answer in an array….

leetcode solution of 1832 in java

Check if the Sentence Is Pangram:- A pangram is a sentence where every letter of the English alphabet appears at least once. Given a string sentence containing only lowercase English letters, returntrue if sentence is a pangram, or false otherwise. Solution:- Flow Diagram:- Code Block:- public static boolean checkIfPangram(String sentence) { Set s = new…

leetcode 1827 solution in java

Minimum Operations to Make the Array Increasing You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1. For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3]. Return the minimum number of operations needed…

leetcode 1816 solution in java

Truncate Sentence A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation). For example, “Hello World”, “HELLO”, and “hello world hello world” are all sentences. You are given a sentence s​​​​​​…

leetcode 1854 solution in java

Maximum Population Year Solution This above problem is taken from https://leetcode.com/problems/maximum-population-year/ Solution:- Approach:- Code:- public static int methodeName(int[][] arr) { //defined one array years with size 2051 int[] years = new int[2051]; //Now hover over the goven 2d array for (int[] log : arr) { //given array is {1952,1961},{1953,1961 } //so for first iteration log…