Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Arrays.asList()

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



prints
Length of the arr=10
Elements in th list =1
***********************
length of the array =5
Elements in the list =5
 
Henry Wong
author
Marshal
Pie
Posts: 21500
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic