How can we convert a JSONArray to String Array in Java?

Manisha Chand
Updated on 06-Jun-2025 12:43:59

4K+ Views

A JSONArray is a class provided by the org.json package that represents a collection of JSON values. These values can be of any type, such as strings, numbers, booleans, or even nested objects or arrays. If you do not know what JSON is, then you can read the JSON tutorial. Converting JSON Array to String ArrayWe can convert a JSONArray to String Array by using a simple loop as shown in the example below - import org.json.*; import java.util.*; public class JsonArraytoStringArrayTest { public static void main(String[] args) { ... Read More

JavaScript Program for Two Pointers Technique

Ravi Ranjan
Updated on 06-Jun-2025 12:33:05

2K+ Views

In this article we are given a sorted array, our task is to find if there exists any pair of elements such that their sum is equal to a given number. Users must be familiar with array, loop and nested loops, and if/else statement. Two Pointers Technique Two pointers technique is a commonly used algorithmic approach to solve various problems that require linear time complexity. This technique is used to find a solution for problems that involve searching, sorting, or manipulating arrays, strings, or linked lists. In this article, we are going to solve the pair sum problem using brute ... Read More

JavaScript Program to Find the Lost Element from a Duplicated Array

Ravi Ranjan
Updated on 06-Jun-2025 12:25:24

1K+ Views

To find the lost element from a duplicated array in JavaScript, we will be discussing various approaches.Prerequisite to solve this problem requires an understanding of JavaScript arrays, loops, set object and binary search. In this article we are having two arrays where one array is duplicate of other with a missing element, our task is to find the lost element from a duplicated array in JavaScript. Example Input: array1 = [1, 2, 3, 4, 5, 6] array2 = [1, 2, 3, 5, 6] Output: Missing element: 4 Approaches to Find the Lost Element Here ... Read More

How To Find the Midpoint of a Line in Java?

Vivek Verma
Updated on 06-Jun-2025 11:01:26

2K+ Views

Midpoint of a Line The midpoint refers to a point that is exactly in the middle of the line segment, which is joined through two points. These are the endpoints of a line segment and the midpoint lying in between these two points. The following diagram will provide a better understanding: Midpoint Formula The midpoint formula is defined for the points in the coordinate axes (i.e., x and y). Let's consider (x1, y1) and (x2, y2) are the endpoints of a line segment. The midpoint will be equal to half of the sum of the x-coordinates of the two ... Read More

How to iterate List Using Streams in Java?

Vivek Verma
Updated on 06-Jun-2025 10:49:25

22K+ Views

In Java, a List is an interface that stores a sequence of elements of similar type. Java provides various ways to iterate over a list, such as using a for loop, forEach loop, iterator object, stream, or forEach() method with a lambda expression. What is Stream in Java? In Java, a Stream is an interface, which represents a sequence of elements (or objects) supporting sequential and parallel aggregate operations. These operations can be used to produce the desired result. The Stream interface provides a method named stream(), which is used to create a sequential stream from the current collection (or ... Read More

How To Find Volume of Hemisphere in Java?

Vivek Verma
Updated on 05-Jun-2025 21:36:00

643 Views

A Hemisphere refers to the exact half of a sphere, which means if we divide a sphere into two equal parts, then we will get two hemispheres. The hemisphere is a three-dimensional geometrical shape that has one flat face. Following is the diagram of the Hemisphere, which gives an idea about the space it occupies and its radius that helps you to calculate the volume: Volume of the Hemisphere The volume of the hemisphere is the amount of space occupied by the hemisphere. It is half of the volume of the sphere with the same radius (r). Here is ... Read More

How To Find Minimum Height of the Triangle with Given Base and Area in Java?

Vivek Verma
Updated on 05-Jun-2025 21:31:57

682 Views

The height of a triangle is the perpendicular distance from a vertex to the line containing the opposite side (which is the base). The height is also known as altitude. What is Minimum Height? The minimum height of a triangle refers to the shortest possible altitude (perpendicular distance) from a vertex to the opposite side (base). The following diagram provides you with a clear idea of the triangle's height and its base: A triangle is a polygon (a basic shape in geometry) that has three sides and three corners. The corners, also called vertices, are zero-dimensional points, while ... Read More

How To Check Whether a Number is a Unique Number or Not in Java?

Vivek Verma
Updated on 05-Jun-2025 21:29:25

11K+ Views

What is Unique Number? A Unique number is a number that does not have a single repeated digit in it. In other words, a number in which all the digits are present exactly only one time. For example, consider the number 12. The digits 1 and 2 each appear only once, the number is unique as it contains all distinct digits. Here are some other examples of unique numbers such as 132, 1, 45, 98, 701, 5, 12, 1234, etc. Input & Output Scenarios Below are the few of the input and output scenarios which gives some idea about ... Read More

How To Check Whether a Number is a Sunny Number or Not in Java?

Vivek Verma
Updated on 05-Jun-2025 21:27:06

8K+ Views

What is Sunny Number? A number is said to be a Sunny number if the square root of the next value of the given number is a perfect square of any number. For example, let's consider the number 3. If we take the number after 3, which is 4, and 2 is its perfect square root. Here are some other examples of sunny numbers such as 3, 8, 15, 24, 35, 48, 63, etc. Input & Output Scenarios Following are some input and output scenarios that provide a better understanding of the sunny number: Scenario 1 Suppose the given input ... Read More

How To Check Whether a Number Is a Niven Number or Not in Java?

Vivek Verma
Updated on 05-Jun-2025 21:24:10

11K+ Views

What is Niven Number? A Niven number is a number that is completely divisible by the sum of its digits. For example, consider the number 20. If we calculate the sum of its digits, 2 + 0, we get 2. When we divide 20 by 2 (20 / 2), the remainder is 0 (which means it is completely divisible). Here are some other examples of Niven numbers such as 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, etc. Input & Output Scenarios The following input and output scenarios will give you an idea of how to ... Read More

Advertisements