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
Articles by Alshifa Hasnain
Page 19 of 23
Java Concurrency – yield() method
In this article, we will learn that concurrency in Java allows multiple threads to execute simultaneously, sharing system resources efficiently. One of the methods provided in the Thread class for managing thread execution is the yield() method. What is the yield() Method? The yield() method is a static method of the Thread class that hints to the thread scheduler that the current thread is willing to pause its execution in favor of other threads of the same or higher priority. It is part of Java's concurrency toolbox and is primarily used for fine-tuning thread execution. Syntax of yield function − ...
Read MoreJava Program to Initialize a List
In this article, we will learn to initialize a list in Java. A list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. Problem Statement Given a scenario where you need to create and initialize a list in Java, the goal is to understand and implement various approaches to initialize lists effectively. Input Initialize an empty list and add elements − "Apple", "Banana", "Cherry" Output ["Apple", "Banana", "Cherry"] Different Approaches Following are the different approaches to Initialize ...
Read MoreJavaScript: take every nth Element of Array and display a fixed number of values?
In this article, we will learn to extract every nth element from an array and display a fixed number of values in Javascript. The objective is to filter out every second element (or more generally every nth element) from an array and limit the result to a specified count of elements. We will explore different approaches in JavaScript for achieving this functionality, each offering a unique way to solve the problem. Problem Statement Let's say you have an array that takes every nth element. Display a fixed number of values after extracting the elements. Input Let’s say the following is ...
Read MoreJavaScript Narcissistic number
In this article, we will learn to check if a number is Narcissistic in JavaScript. A Narcissistic number is a number that equals the sum of its digits, each raised to the power of the total number of digits. We will explore two approaches to solve this problem an iterative method and a concise string manipulation technique. Narcissistic number A narcissistic number(also known as an Armstrong number) in a given number base b is a number that is the sum of its digits each raised to the power of the number of digits. For example − 153 = 1^3 + ...
Read MoreJava Program to enable cell selection in a JTable
In this article, we will learn to enable cell selection in a JTable in Java Swing. By default, JTable allows row or column selection, but enabling cell selection gives users the ability to select individual cells. This feature is useful for tasks that require precise control over table data, such as editing or copying specific values. Approach for Enabling Cell Selection in JTableThe goal is to create a JTable where users can select individual cells, rather than just rows or columns. The approach focuses on: Creating the JTable: We define a table with data ...
Read MoreJavaScript - array undefined element count
In this article, we will learn to count the number of undefined elements in an array using JavaScript. When working with arrays in JavaScript, you may encounter situations where certain elements are either explicitly set as undefined or are missing altogether (often represented by empty slots in sparse arrays). Problem Statement Given an array that may contain undefined values, we need to count how many elements in the array are defined (i.e., not undefined). Input const arr = [12, undefined, "blabla", , true, 44]; Output 44 elements are defined (12, "blabla", true, and 44). Thus, the expected output is ...
Read MoreJavaScript equivalent of Python\'s zip function
In this article, we will learn the JavaScript equivalent of Python's zip Function In Python, the zip() function is a convenient way to combine multiple tables into a single iterable of tuples. However, JavaScript does not have a built-in equivalent for this functionality Problem Statement Given two or more arrays of equal length, implement a function in JavaScript that combines these arrays into a single variety of arrays, where each inner array contains the elements from the input arrays at the corresponding positions. Input arr1 = [1, 2, 3], arr2 = ['a', 'b', 'c']Output [[1, 'a'], [2, 'b'], [3, 'c']] ...
Read MoreJavaScript: How to loop through all DOM elements on a page and display result on console?
In this article, we will learn how to iterate through all DOM elements on a webpage using JavaScript. By doing so, we can easily access and manipulate various elements of the page, whether for debugging, gathering information, or applying changes to the page's structure and content. We'll walk through a step-by-step process to loop through all elements and display the results in the console, helping you better understand how to interact with the DOM. What is the DOM? The Document Object Model (DOM) is a representation of the structure of a webpage. It treats each part of the webpage (HTML ...
Read MoreJava Program to Print Upper Star Triangle Pattern
In this article, we will learn to print the upper star triangle pattern in Java. Printing patterns is a common exercise to strengthen the understanding of loops in programming. One of the most popular patterns is the Upper Star Triangle, which visually resembles an inverted right-angled triangle of stars aligned from the top. Below is a demonstration of the same − Input Enter the number of rows : 8 Output The upper star triangle star pattern : * ...
Read MoreJava Program to convert integer to String with Map
In this article, we will learn to convert integers to String with Map in Java. The Stream API has become an essential tool for processing collections of data in a more declarative and readable way. Instead of using traditional loops, streams allow developers to filter, map, and perform other operations on data with minimal code Problem Statement Given an integer, we need to convert it to its string representation where the integer is treated as a character (e.g., 5 becomes "5", 10 becomes "10"). We'll use a Map to define the integer-to-string mappings and retrieve the string equivalent for a ...
Read More