Примитивные типы не могут конвертироваться в Wrapper для ArrayListJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Примитивные типы не могут конвертироваться в Wrapper для ArrayList

Сообщение Anonymous »


I've been trying to learn how to use ArrayLists, however when I try to add primitive type values they don't convert to wrapper types in this machine.

import java.util.ArrayList; import java.util.Scanner; public class IntegerListTest { public static void main(String[] args) { Scanner scan = new Scanner(System.in); ArrayList integerList = new ArrayList(); ArrayList integerListB = new ArrayList(); int n = 1; if (n > 0 && n < 100) { while ((n > 0) && (n < 100)) { System.out.println("Inserire numero"); n = scan.nextInt(); if (n > 0 && n < 100) { integerList.add(valueOf(n)); if (integerListB.contains(n) == false) integerListB.add(n); } } } System.out.println(integerList); System.out.println(integerListB); } } For example in this code the int inputs can't convert to Integers. I tried on another computer and it works just fine and I don't know why.


Источник: https://stackoverflow.com/questions/781 ... -arraylist
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»