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
Java Articles
Page 179 of 450
Java program to get the prime numbers with BigInteger type
In this article, we will learn how to generate prime numbers using the BigInteger class in Java. A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. Here, we have the BigInteger type, which has operations for modular arithmetic, GCD calculation, primality testing, prime generation, etc. Steps to get the prime numbers with BigInteger type Following are the steps to get the prime numbers with BigInteger type − First, we will import the BigInteger from the java.math package. ...
Read MoreJava program to subtract week from current date
In this article, we will learn to subtract the week from the current date using Java. This is useful when you need to manipulate dates, such as calculating dates from previous weeks for scheduling or tracking purposes. We'll use two approaches: using the Calendar class and the LocalDate class, showcasing how to easily adjust dates. Problem Statement Write a program in Java to subtract a specified number of weeks from the current date and display the updated date − Input Run the program Output Current Date = Mon Nov 04 09:41:18 IST 2024 Updated Date = Mon Oct 21 09:41:18 ...
Read MoreDelete middle element of a stack in Java
In order to delete the middle element of a stack, then first we need to remove the elements above the middle element. After removing the middle element, we restore the elements above it to maintain the original sequence. We can achieve this using a recursive approach, as explained step-by-step below. We cannot delete the middle element of the stack directly because, according to the stack property, we can perform only push and pop operations on the top of the stack. Steps to Delete the Middle Element of a Stack Step 1: Determine the Position of the Middle Element, First ...
Read MoreMinimum number of jumps to reach end using Java
In this article, we will learn how to solve the "Minimum Number of Jumps to Reach the End" problem using Java. Let's break it down step-by-step. The idea is to find the smallest number of jumps needed to get from the start to the end of an array. Each element in the array represents the maximum number of steps you can take from that position. Problem StatementGiven an array arr[], where each element represents the maximum number of steps you can move forward from that position, the goal is to start from the beginning of the array and ...
Read MoreJava program to put value to a Properties list
In this article, we will learn how to use the Properties class in Java to store and display key-value pairs. The Properties class is useful for handling configuration settings or storing data in a structured way, where both keys and values are strings. By using the put() method, we can easily add values to a property list and later retrieve or display these key-value pairs. This approach provides a simple and efficient way to manage data in a key-value format in Java applications. Problem Statement A properties list contains country-year pairs. Write a Java program to store values ...
Read MoreJava program to sort the elements of the stack in descending order
In this article, we will learn to sort the elements of the stack in descending order. A stack is a data structure that works on the LIFO (Last In First Out) principle which means that the last added item is removed first. One real-life example of a stack is browser history where the last used website appears first. In this article, we are going to discuss, how we can sort the element of stack in descending order in Java. Problem Statement In the given problem, we have a stack of unsorted integer elements, which we have to sort in descending ...
Read MoreJava program to merge duplicates of a List with TreeSet
In this article, we will learn to merge duplicate elements from a List in Java by using a TreeSet. This program will take a List of strings containing duplicate values, transfer the elements into a TreeSet, and display the unique, sorted elements. Using a TreeSet is ideal here because it automatically removes duplicates and orders the elements in natural order. Problem Statement Write a Java program to remove duplicate elements from a list using a TreeSet. The program should take a list with repeated elements, convert it into a TreeSet to eliminate duplicates, and display the unique, sorted elements. Input ...
Read MoreJava program to sort a List in case sensitive order
In this article, we will learn to sort a List in case-sensitive order in Java. Sorting in case-sensitive order places uppercase letters before lowercase letters (e.g., 'A' before 'a'), meaning that uppercase letters are prioritized in sorting. This program uses Java’s built-in Collections.sort method to arrange elements in this specific order. Problem Statement Given a list of mixed uppercase and lowercase letters, write a Java program that sorts the list in a case-sensitive order. Input { "P", "W", "g", "K", "H", "t", "E" } Output List = [P, W, g, K, H, t, E] Case Sensitive Sort = [E, H, ...
Read MoreJava program to get the reverse of an Integer array with Lambda expressions
In this article, we will learn to get the reverse of an Integer array with Lambda expressions in Java. By utilizing the Arrays.sort() method along with a custom comparator defined as a lambda expression, we can efficiently reorder the elements of the array in descending order. Lambda expressions are a concise way to represent functional interfaces, allowing you to write cleaner and more readable code. Problem Statement Write a program in Java to get the reverse of an Integer array with Lambda expressions − Input arr = {20, 50, 75, 100, 120, 150, 170, 200} Output Integer Array elements... 20 50 ...
Read MoreJava program to print matrix in Z form
In this article, we will learn to print a matrix in a "Z" pattern in Java. It starts from the top-left corner, moves horizontally across the top row, then diagonally down through the center, and finally across the bottom row. This pattern creates a "Z" shape with selected elements from the matrix. Problem Statement Write a program in Java to print a matrix in Z form. Input my_arr[][] = { { 34, 67, 89, 0}, { 0, 1, 0, 1 }, { 56, 99, 102, 21 }, {78, 61, 40, 99}} Output The matrix is34 67 89 0 0 99 ...
Read More