Java Articles

Page 118 of 450

How to compare two ArrayList for equality in Java?

Srinivas Gorla
Srinivas Gorla
Updated on 11-Mar-2026 14K+ Views

You can compare two array lists using the equals() method of the ArrayList class, this method accepts a list object as a parameter, compares it with the current object, in case of the match it returns true and if not it returns false.Exampleimport java.util.ArrayList; public class ComparingList {    public static void main(String[] args) {       ArrayList list1 = new ArrayList();       list1.add("JavaFx");       list1.add("Java");       list1.add("WebGL");       list1.add("OpenCV");       ArrayList list2 = new ArrayList();       list2.add("JavaFx");       list2.add("Java");       list2.add("WebGL");       list2.add("OpenCV");       System.out.println(list2);       System.out.println(list1.equals(list2));    } }

Read More

How to convert a list collection into a dictionary in Java?

Nikitha N
Nikitha N
Updated on 11-Mar-2026 2K+ Views

Following is an example to convert a list collection into a dictionary in Java.Exampleimport java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; public class CollectionDictionary {    public static void main(String[] args) {       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       System.out.println(list);       Dictionary dictionary = new Hashtable();       Hashtable hashTable = new Hashtable();       hashTable.put(1, list.get(0));       hashTable.put(2, list.get(1));       hashTable.put(3, list.get(2));       hashTable.put(4, list.get(3));       System.out.println(hashTable);    } }Output[JavaFx, Java, WebGL, OpenCV] {4=OpenCV, 3=WebGL, 2=Java, 1=JavaFx}

Read More

Fibonacci series program in Java without using recursion.

Syed Javed
Syed Javed
Updated on 11-Mar-2026 4K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {        int n1 = 0, n2 = 1, n3, i, max = 5;        System.out.print(n1 + " " + n2);        for (i = 2; i < max; ++i) {           n3 = n1 + n2;           System.out.print(" " + n3);           n1 = n2;           n2 = n3;        }     }  }Output0 1 1 2 3

Read More

Fibonacci series program in Java without using recursion.

Syed Javed
Syed Javed
Updated on 11-Mar-2026 4K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {        int n1 = 0, n2 = 1, n3, i, max = 5;        System.out.print(n1 + " " + n2);        for (i = 2; i < max; ++i) {           n3 = n1 + n2;           System.out.print(" " + n3);           n1 = n2;           n2 = n3;        }     }  }Output0 1 1 2 3

Read More

Prime number program in Java.

V Jyothi
V Jyothi
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {       int i, m = 0, flag = 0;       int n = 41;// it is the number to be checked       m = n / 2;       if (n == 0 || n == 1) {          System.out.println(n + " not a prime number");       } else {          for (i = 2; i

Read More

Prime number program in Java.

V Jyothi
V Jyothi
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    public static void main(String args[]) {       int i, m = 0, flag = 0;       int n = 41;// it is the number to be checked       m = n / 2;       if (n == 0 || n == 1) {          System.out.println(n + " not a prime number");       } else {          for (i = 2; i

Read More

Factorial program in Java without using recursion.

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    static int factorial(int n) {       if (n == 0)          return 1;       else          return (n * factorial(n - 1));    }    public static void main(String args[]) {       int i, fact = 1;       int number = 5;       fact = factorial(number);       System.out.println(number + "! = " + fact);    } }Output5! = 120

Read More

Factorial program in Java without using recursion.

Vikyath Ram
Vikyath Ram
Updated on 11-Mar-2026 2K+ Views

Following is the required program.Examplepublic class Tester {    static int factorial(int n) {       if (n == 0)          return 1;       else          return (n * factorial(n - 1));    }    public static void main(String args[]) {       int i, fact = 1;       int number = 5;       fact = factorial(number);       System.out.println(number + "! = " + fact);    } }Output5! = 120

Read More

Single level inheritance in Java

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 15K+ Views

Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Exampleclass Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } public class Tester {    public static void main(String[] arguments) {       Rectangle rect = new Rectangle();       rect.display();       rect.area();    } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.

Read More

Single level inheritance in Java

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 15K+ Views

Single Level inheritance - A class inherits properties from a single class. For example, Class B inherits Class A.Exampleclass Shape {    public void display() {       System.out.println("Inside display");    } } class Rectangle extends Shape {    public void area() {       System.out.println("Inside area");    } } public class Tester {    public static void main(String[] arguments) {       Rectangle rect = new Rectangle();       rect.display();       rect.area();    } }OutputInside display Inside areaHere Rectangle class inherits Shape class and can execute two methods, display() and area() as shown.

Read More
Showing 1171–1180 of 4,498 articles
« Prev 1 116 117 118 119 120 450 Next »
Advertisements