public static Map < String , String > getSubmap ( Map < String , String > mapIn , String subkey ) { if ( mapIn == null || mapIn . isEmpty ( ) ) { return Collections . emptyMap ( ) ; } // Get map sub-element. return mapIn . entrySet ( ) . stream ( ) . filter ( entry -> entry . getKey ( ) . toLowerCase ( ) . startsWith ( subkey . toLowerCase ( ) ) ) . map ( entry -> { String newKey = entry . getKey ( ) . substring ( subkey . length ( ) , entry . getKey ( ) . length ( ) ) ; return new AbstractMap . SimpleImmutableEntry <> ( newKey , entry . getValue ( ) ) ; } ) . collect ( Collectors . toMap ( Entry :: getKey , Entry :: getValue ) ) ; }
Takes map and produces a submap using a key .