0
Create a arraylist that can store only number like int,float,double,etc without any other data type
6 Answers
+ 2
...
ArrayList<Double> listName = new ArrayList<Double>();
// Š½Š°ŠæŠ¾Š»Š½ŃŠµŠ¼ Š¼Š°ŃŃŠøŠ² Š“Š°Š½Š½ŃŠ¼Šø
listName.add(3.14);
listName.add(28.54);
listName.add(0.265333333);
listName.add(1.00009);
for (int i = 0; i < listName.size(); i++) System.out.println(listName.get(i));
...
0
import java.util.List;
import java.util.ArrayList;
public class Example {
public static void main(String[] args) {
List<Integer> arrayList = new ArrayList();
arrayList.add(42);
System.out.println(arrayList);
}
}
https://www.google.com/amp/s/www.geeksforgeeks.org/list-interface-java-examples/amp/
https://www.w3schools.com/java/java_arraylist.asp
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
https://docs.oracle.com/javase/8/docs/api/java/util/List.html
0
https://code.sololearn.com/cm0LsD6W3VaU/?ref=app
0
...
ArrayList<String> listName = new ArrayList<String>();
// Š½Š°ŠæŠ¾Š»Š½ŃŠµŠ¼ Š¼Š°ŃŃŠøŠ² Š“Š°Š½Š½ŃŠ¼Šø
listName.add("blabla");
listName.add("ohhoho");
listName.add("abrakadabra");
listName.add("tararam");
for (int i = 0; i < listName.size(); i++) System.out.println(listName.get(i));
...
0
import java.util.*;
class Numbersonly{
private long num;
private double num1;
Numbersonly(int n,double d){
num=n;
num1=d;
}
public String toString() {
return +num +"\n"+ num1;
}
}
public class assignment2 {
public static void main(String args[]) {
ArrayList<Numbersonly> al=new ArrayList<Numbersonly>();
al.add(new Numbersonly(2,4.5));
al.add(new Numbersonly(7,8.0));
al.add(new Numbersonly(8923,0.07));
for(Numbersonly element:al)
System.out.println(element + "\n");
}
}
- 1
...
ArrayList<String> listNameString = new ArrayList<String>();
ArrayList<Integer> listNameInteger = new ArrayList<Integer>();
ArrayList<Double> listNameDouble = new ArrayList<Double>();
ArrayList<String, Integer> list = new ArrayList<String, Integer>();
....