• Post Reply Bookmark Topic Watch Topic
  • New Topic

How TreeSet.subSet works?  RSS feed

 
Byeonggon Lee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The result is:
[1, 2, 3, 6, 9] [1, 2, 3, 6]


I don't know why 'subs' is affected by 's.add(3)'

May be it is related to how the method subSet works

Can you tell my the reason?? thanks


 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byeong Gon Lee wrote:I don't know why 'subs' is affected by 's.add(3)'

Because it says so in the docs. Specifically:
"The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa."

Winston
 
Byeonggon Lee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!