Example:
package javanumber; import java.util.ArrayList; import java.util.List; /** * * @web http://java-buddy.blogspot.com/ */ public class JavaNumber { public static void main(String[] args) { List<Number> numberList = new ArrayList<>(); numberList.add((int)123); numberList.add(123456.7); numberList.add((double)456.789); numberList.add(0.1f); for(Number num:numberList){ System.out.println(num + " of type " + num.getClass()); } } }
A single List contain numbers of Integer, Double and Integer |
No comments:
Post a Comment