• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

kb 6 book selt test question doubt ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please consider the following snippet of code from the self test questions of kb 6 at page no. 656 , question 12 , chapter collections and generics



according to me the size of subs should be 2, because when the did s.add("c2") , as far as i think c2 does not fall in the range of b and d. but on the contrary book says answer is 3 , because subs will contain [c,c2,d]. the book says "the final add viz s.add("c2") is in range of both the tree sets . i would like to know how is this possible ? what do you mean by range ?
 
Henry Wong
author
Marshal
Pie
Posts: 21417
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gurpeet singh wrote:Please consider the following snippet of code from the self test questions of kb 6 at page no. 656 , question 12 , chapter collections and generics



according to me the size of subs should be 2, because when the did s.add("c2") , as far as i think c2 does not fall in the range of b and d. but on the contrary book says answer is 3 , because subs will contain [c,c2,d]. the book says "the final add viz s.add("c2") is in range of both the tree sets . i would like to know how is this possible ? what do you mean by range ?



The tree set sorts the elements -- so for something to be in range, it has to be greater than the minimum value and less then the maximum value of the range (and since your example has inclusive set to true, if can be equal to the min or max as well).

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