1. Print Mostly occurred string in Hello String import java.util.Map ; import java.util.Optional ; import java.util.stream.Collectors ; public class MostOccuringCharacter { // print most occuring character in hello string and write program to use optional public static void main ( String [] args ) { String str = "Hello" ; Optional < Map . Entry < Character , Long >> character = str .chars() .mapToObj( x -> ( char ) x ) .collect( Collectors . groupingBy ( x -> x , Collectors . counting ())) .entrySet() .stream() .max( Map . Entry . comparingByValue ()); if ( character .isPresent()){ System . out .println( "Most occurring character: " + character .get().getKey()); } //or character .ifPresent( c -> System . out .println( "Most occurring character: " + c .getKey())); } }