Articles on Trending Technologies

Technical articles with clear explanations and examples

Custom UnaryOperator implementation in java.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 514 Views

The java.util.function.UnaryOperator interface and can be used as assignment target for lambda expressions, it represents operation on a single operand whose result will be of same type as the input. We can create our own UnaryOperator by implementing this interface.The replaceAll() method of the List interface accept an object of the UnaryOperator representing a particular operation performs the specified operation on all the elements of the current list and replaces the existing values with the resultant values.In the following example we are implementing the UnaryOperator interface and creating a custom unary operator object and trying to pass it as an ...

Read More

Find the second last node of a linked list in single traversal in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 744 Views

Now we will see how to get the second last element in the linked list. Suppose there are few elements like [10, 52, 41, 32, 69, 58, 41], second last element is 58.To solve this problem, we will use two pointers one will point to current node, and another will point to previous node of the current position, then we will move until the next of current is null, then simply return the previous node.Example#include using namespace std; class Node {    public:       int data;       Node *next; }; void prepend(Node** start, int new_data) { ...

Read More

Regular expression for a hexadecimal number greater than 10 and should be even in length in java.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 440 Views

Following is the regular expression to match hexadecimal number greater than 10 with even length −^(?=.{10,255}$)(?:0x)?\p{XDigit}{2}(?:\p{XDigit}{2})*$Where,^ − Matches the starting of the sentence.(?=.{10,255}$) − String ending with characters with 10 to 255.\p{XDigit}{2} − Two hexa-decimal characters.(?:\p{XDigit}{2})* − 0 or more sequences of double hexa-decimal characters.$ − Matches the end of the sentence.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class JavaExample51 {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       String nums[] = new String[5];       for(int i=0; i

Read More

Shuffle an Array using STL in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 888 Views

Here we will see the Shuffle and random_shuffle in C++. These functions are used to shuffle array elements in C++. We can use the vector also instead of arrays, the usage is similar. Let us see the random_shuffle() first. It is used to randomly rearrange the elements in range [left, right). This function randomly swaps the positions of each element with the position of some randomly chosen positions.We can provide some random generator function to tell which element will be taken in every case. If we do not provide some, it will use its own random generator function.Example#include using ...

Read More

Java regex program to verify whether a String contains at least one alphanumeric character.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

Following regular expression matches a string that contains at least one alphanumeric characters −"^.*[a-zA-Z0-9]+.*$";Where, ^.* Matches the string starting with zero or more (any) characters.[a-zA-Z0-9]+ Matches at least one alpha-numeric character..*$ Matches the string ending with zero or more (ant) characters.Example 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    public static void main(String args[]) {       //Reading String from user       System.out.println("Enter a string");       Scanner sc = new Scanner(System.in);       String input = sc.nextLine();       //Regular expression       String regex = "^.*[a-zA-Z0-9]+.*$";     ...

Read More

upper_bound in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 200 Views

Here we will see that is the upper_bound() function in C++ STL. This function returns an iterator that points to the first element in the container, which is considered to go after val. The syntax is like:iterator upper_bound (const value_type& val); const_iterator upper_bound (const value_type& val) const;The return value is an iterator, pointing to the first element in the container which is considered to go after val.Example#include #include using namespace std; int main () {    set myset;    set::iterator itlow, itup;    for (int i = 1; i < 10; i++) myset.insert(i*10);    itup = myset.upper_bound (60); ...

Read More

Print all triplets with given sum in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 336 Views

In this problem, we are given an array of unique integers and a sum. And we have to find the triplets which can form the same sum.Let's take an example to solve the problem −Input : array = {0 , 2 , -1 , 1, -2} Sum = 1 Output : 1 2 -2 0 2 -1To solve this problem, we will be finding all the triplets that provide the sum. A simple approach will be using three loops and finding the sum of the elements and return the adequate triplet.Example#include using namespace std; void Triplets(int arr[], int n, ...

Read More

Construct a complete binary tree from given array in level order fashion in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have an array A[], with n elements. We have to construct the binary tree from the array in level order traversal. So the elements from the left in the array will be filled in the tree level-wise starting from level 0. So if the array is like A = [1, 2, 3, 4, 5, 6], then the tree will be like below:If we see closer, we can find that when the parent is present at index i, then its two children will be at index (2i + 1), and (2i + 2). Thus we can insert left and ...

Read More

Java regex program to add space between a number and word in Java.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 2K+ Views

You can form matched groups in the regular expression by separating the expressions with parenthesis. In following regular expression the first group matches digits and the second group matches the English alphabet −(\d)([A-Za-z])In short, it matches the part in the input string where a digit followed by an alphabet.Since the expression $1 indicates Group1 and $2 indicates Group2, if you replace The above Java regular expression with $1 $2, using the replace() method (of the String class) a space will be added between number and a word in the given input string when a number is followed by a word.Exampleimport ...

Read More

Print all triplets in sorted array that form AP in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 302 Views

In this problem, we are given a sorted array of numbers and we need to find the triplets with are in the form of arithmetic progression.An arithmetic progression is a series of numbers in which the difference between consecutive terms is the same.Let’s take an example to understand the problem better −Input : array = {2 , 5 , 7, 8 , 9 , 10} Output : 2 5 8 5 7 9 7 8 9 8 9 10To solve this problem, a simple solution would be running three loops and checking all triplets if they are in AP. but ...

Read More
Showing 28401–28410 of 61,297 articles
Advertisements