JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label TreeMap. Show all posts
Showing posts with label TreeMap. Show all posts

what is treemap in java collection with examples

2:50 AM
TreeMap in java with examples TreeMap class implements Map similar to HashMap. Some important points about TreeMap: TreeMap implements Map interface and extends HashMap class. TreeMap is implemented using Red black tree based NavigableMap. TreeMap is ordered collection and store its elements in natural ordering of keys. Key which you would like to put in TreeMap must implement Comaparable interface or you can use Comparator for custom sorting Example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29   package org . arpit . java2blog ;   import java . util . TreeMap ;   public class TreeMapMain {   public static void main ( String args [ ] ) { // TreeMap with Country as key and capital as value // TreeMap stores elements in natural ordering of keys. TreeMap < String , String > co...

.