Search code examples
javacollectionsstring-comparisontreeset

Java Collection framework TreeSet


In TreeSet class of Collection framework, how do the two strings namely "Shiv" and "Shiva" will be compared as in this case "Shiv" does not have fifth letter and before that all are same as of "Shiva"?


Solution

  • @Isha : If you want to know internal working of treeSet from the point of curiosity then you can refer:

    http://javahungry.blogspot.com/2015/10/how-treeset-works-internally-in-java-interview-questions.html

    And, if you want some custom implemetation then you can refer :

    How to implement a TreeSet in Java?

    I hope this helps!