Home Tutorialhelp Comment Argument type error in line list.add() Method

 
 

Comment

Prasanta Panda
Argument type error in line list.add() Method,
December 17, 2008 at 1:50 AM

import java.util.*;
import java.io.*;

public class ShufflingListAndArray{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("How many elements you want to add to the list: ");
int n = Integer.parseInt(in.readLine());
System.out.print("Enter " + n + " numbers to sort: ");
List<Integer> list = new ArrayList<Integer>();
for(int i = 0; i < n; i++){
list.add(Integer.parseInt(in.readLine()));
}
Collections.shuffle(list);
Collections.sort(list);
System.out.println("List sorting :"+ list);
}
}

Hi,
line-> list.add(Integer.getInteger(in.readLine())); here List object has declare to hold Interger type using java generics. But Interger.parseInt(String) returns java primitive int.so it gives datatype compatibility while compiling. ofcourse this is small logical bugs.

Thanks,

View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Advertisements Advertisements
 

 

 

DMCA.com