jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Arrays.asList() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Arrays.asList()" Watch "Doubt in Arrays.asList()" New topic

Doubt in Arrays.asList()

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

In my program I have taken two arrays one is String[] array another is int[] array .When I convert these two arrays into List through Arrays.asList().
But list which is created from int[] has the size that is not equal to the array length,but the that is created from String[] has the same size as the length of the String[].Why the size of the list that is created from int[] array is one?

Length of the arr=10
Elements in th list =1
length of the array =5
Elements in the list =5
Henry Wong

Joined: Sep 28, 2004
Posts: 20359

The asList() method requires an array of objects. An array of ints is *not* an array of objects. However, since the method is written to take var-args, it takes an array of one object -- the int array. Hence, the list of size one.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link: http://aspose.com/file-tools
subject: Doubt in Arrays.asList()
It's not a secret anymore!