I have used simple HashSet to store numbers. I have simply added 0 to 99999 numbers to HashSet . But after 65535 , HashSet is not sorted but some different pattern is observed. Why Collection is not sorted although I am adding numbers which are already sorted.Why such different pattern is observed after 65535 ? does 65535 indicates something from this example ?
Code:
import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
HashSet<Integer> hsset=new HashSet<>();
for(int i=0;i<100000;i++)hsset.add(i);
for(int i:hsset){
System.out.print(i+" ");
}
}
}
Difference in Output from 65535:
65507 65508 65509 65510 65511 65512 65513 65514 65515 65516 65517 65518 65519 65520 65521 65522 65523 65524 65525 65526 65527 65528 65529 65530 65531 65532 65533 65534 65535 65537 65536 65539 65538 65541 65540 65543 65542 65545 65544 65547 65546 65549 65548 65551