This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in Arrays.asList()  RSS feed

 
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
Sheriff
Posts: 23283
125
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
Boost this thread!