Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Found 5,881 articles
How to check Minlength and Maxlength validation of a property in C# using Fluent Validation?
FluentValidation is a popular .NET validation library that provides an easy way to validate model properties. The MinLength and MaxLength validators ensure that string properties meet specific length requirements, making them essential for input validation scenarios. Syntax Following is the syntax for using MaximumLength validator − RuleFor(x => x.PropertyName).MaximumLength(maxValue); Following is the syntax for using MinimumLength validator − RuleFor(x => x.PropertyName).MinimumLength(minValue); MaxLength Validator The MaximumLength validator ensures that the length of a string property does not exceed the specified maximum value. This validator is only valid on string properties. ...
Read MoreHow to create JLabel to hold multiline of text using HTML in Java?
In Java Swing, the JLabel component by default displays only single-line text. To create a JLabel that can hold multiple lines of text, we need to use HTML formatting within the label text. This allows us to use HTML tags like for line breaks and other HTML formatting elements. Syntax Following is the syntax to create a multiline JLabel using HTML − JLabel label = new JLabel("Line1Line2"); For more complex formatting with alignment − JLabel label = new JLabel("Line1Line2", JLabel.LEFT); How It Works When a JLabel's text starts ...
Read MoreHow to do case insensitive string comparison of strings in JavaScript
In this tutorial, we will learn how to do a case-insensitive string comparison of strings in JavaScript. Case insensitive comparison means strings should be considered equal regardless of whether they are written in lowercase or uppercase letters. This technique is commonly used in search functionality, where "TutorialsPoint" and "tutorialspoint" should be treated as identical. There are four main methods to perform case-insensitive string comparisons: toUpperCase() toLowerCase() localeCompare() RegExp() Using the toUpperCase() Method The toUpperCase() method converts all alphabetic ...
Read MoreImplementing block search in JavaScript
Block Search is a searching algorithm for sorted arrays that improves upon linear search by jumping ahead in fixed steps rather than checking every element. It combines the efficiency of skipping elements with linear search for the final location. How Block Search Works The algorithm divides the array into blocks of size √n and performs these steps: Jump through blocks of size √n until finding a block where the target might exist Perform linear search within that specific block Return the index if found, or -1 if not found Block Search ...
Read MoreInverting a binary tree in JavaScript
Inverting a binary tree means creating a mirror image where all left and right child nodes are swapped recursively. This is a classic tree manipulation problem that demonstrates recursion and tree traversal concepts. What is a Binary Tree? A binary tree is a hierarchical data structure where each node has at most two children: left and right. The topmost node is called the root, and nodes with no children are called leaves. 4 2 7 ...
Read MoreJavaScript array sorting by level
In this article, we will learn array sorting by level in JavaScript, creating a hierarchical tree structure from a flat array is a common challenge when dealing with relational data. This is a common task when dealing with hierarchical data, such as organizational charts, category trees, or file systems, where relationships like parent-child need to be represented. Problem Statement We have an array of objects representing nodes with _id, level, and parentId properties. Our goal is to transform this array into a tree structure where nodes are nested as children under their respective parents. The elements with the ...
Read MoreCalculate Subtraction of diagonals-summations in a two-dimensional matrix using JavaScript
Suppose we have a square matrix represented by a 2-D array in JavaScript like this: const arr = [ [1, 3, 5], [3, 5, 7], [2, 4, 2] ]; console.log(arr); [ [ 1, 3, 5 ], [ 3, 5, 7 ], [ 2, 4, 2 ] ] We need to write a JavaScript function that calculates the absolute difference between the sum of elements on the two diagonals of the matrix. Understanding the Diagonals In a square matrix, there are two diagonals: ...
Read MoreHow to validate if an element in an array is repeated? - JavaScript
We are required to write a JavaScript function that takes in two arguments: An Array, say arr, of literals that may contain some repeating elements. A number, say limit. The function should validate that no element of the array is repeated more than limit number of times. If any element is repeated more than the limit the function should return false, true otherwise. Using Object to Count Occurrences The most efficient approach is to use an object to count each element's occurrences, then check if any count exceeds ...
Read MoreCompare and fill arrays - JavaScript
We are required to write a function that compares two arrays and creates a third array filling that array with all the elements of the second array and filling null for all those elements that are present in the first array but misses out in the second array. For example − If the two arrays are − const arr1 = ['f', 'g', 'h']; const arr2 = ['f', 'h']; Then the output should be − const output = ['f', null, 'h']; Algorithm Approach The solution uses an offset variable to ...
Read MoreHow to select the middle of an array? - JavaScript
We are required to write a JavaScript function that takes in an array of numbers and returns the middlemost element(s) of the array. For arrays with odd length, there's one middle element. For arrays with even length, there are two middle elements. For example, if the array is: const arr = [1, 2, 3, 4, 5, 6, 7]; Then the output should be [4] (the middle element at index 3). Using Array Prototype Method We can extend the Array prototype to add a middle() method that returns the middle element(s): ...
Read More