Let’s learn how to remove last element from arraylist in java. How to remove last element from ArrayList in java To remove last element from arraylist use two overloaded remove() method of ArrayList. They are, Here’s an example on remove(int index) to last element from arraylist. import java.util.ArrayList; import java.util.List; public class ArrayListRemoveLastElement { public…

Read More How to remove last element from ArrayList in java

Let’s learn java program to find maximum and minimum number without using array. Java program to find maximum and minimum number without using array In the below example we are using Integer.MAX_VALUE and Integer.MIN_VALUE to find maximum value and minimum number without using array. Here’s the java program. import java.util.Scanner; public class MaximumMinimumWithoutArray { public…

Read More Java program to find maximum and minimum number without using array

Let’s learn program to find area of rectangle using inheritance in java. Program to find area of rectangle using inheritance in java We can find area of rectangle using inheritance. Here’s an example. class RectangleDimension { int length; int breadth; } class Rectangle extends RectangleDimension { int area; void findArea() { area = length *…

Read More Program to find area of rectangle using inheritance in java

Let’s learn java program to find area of circle and rectangle using interface. Java program to find area of circle and rectangle using interface We can use interface to find area of circle and rectangle. Here’s the java program. interface FindArea { double pi = 3.14159265359; double calculate(double a, double b); } class Rectangle implements…

Read More Java program to find area of circle and rectangle using interface

Let’s learn java program to calculate area of circle rectangle and triangle using switch. Java program to calculate area of circle rectangle and triangle using switch We can use switch statement to calculate area of circle, rectangle and triangle. import java.util.Scanner; public class FindAreaUsingSwitchStatement { public static void main(String[] args) { Scanner sc = new…

Read More Java program to calculate area of circle rectangle and triangle using switch

Let’s learn swap three variables in java without temporary variable. Swap three variables in java without using temporary variable In the below example we are using arithmetic operators to swap three variables without temporary variable. public class SwapThreeNumbersWithoutTemp { static int num1, num2, num3; public static void main(String[] args) { num1 = 30; num2 =…

Read More Swap three variables in java without temporary variable

Let’s learn how to sort TreeSet in descending order in java. How to sort TreeSet in descending order in java In this post lets sort TreeSet elements in descending order or decreasing order. For this we are using descendingSet() method. This method returns a reverse order view of the elements contained in this set. import…

Read More How to sort TreeSet in descending order in java