The following example code demonstrates How to Create ArrayList of Numeric Types in Java.

Here is a Java program that implements the given requirement.

import java.util.ArrayList;
import java.util.Iterator;

public class Main {
  public static void main(String[] args) {
    ArrayList<Number> list = new ArrayList<>();
    list.add(10);
    list.add(10.5f);
    list.add(100.5);
    list.add(1000L);
    list.add((byte) 50);

    Iterator<Number> iterator = list.iterator();
    while (iterator.hasNext()) {
      System.out.println(iterator.next());
    }
  }
}

This program creates an ArrayList of type Number called list, adds 5 elements of different numeric types (int, float, double, long, and byte) to it, and then creates an iterator iterator using the iterator() method of the ArrayList. The elements of the list are displayed using a while loop, in which the iterator.hasNext() method returns true until there are no more elements in the list, and the iterator.next() method returns the next element in the list. Note that the ArrayList only contains elements of numeric types, as specified in the requirement.



Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise

programmingempire

Princites