public static < V > int longestKeyLength ( Map < String , V > map ) { if ( map . isEmpty ( ) ) { return 0 ; } return Ordering . natural ( ) . max ( FluentIterable . from ( map . keySet ( ) ) . transform ( StringUtils . lengthFunction ( ) ) ) ; }
Returns the length of the longest key in a map or 0 if the map is empty . Useful for printing tables etc . The map may not have any null keys .