I have the code:
int x:
ArrayList < Short> lista;
How do I convert x to Short to be able to add it to the dynamic array list by using the statement list.add
I have the code:
int x:
ArrayList < Short> lista;
How do I convert x to Short to be able to add it to the dynamic array list by using the statement list.add
You can perform a cast of the variable, that is, before saving it, change the data type:
(short) x;
Make the change from x to int .
import java.util.ArrayList;
public class Aplicacion {
public static void main(String[] args) {
int x = 30;
int y = 40;
ArrayList<Short> lista = new ArrayList<Short>();
lista.add((short) x);
lista.add((short) y);
}
}