0% found this document useful (0 votes)
6 views

List Implemented Classes

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

List Implemented Classes

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Sessions 15-03-2024.

List Implemented Classes

Map Interface: key value pair, where keys are always unique and values may be duplicate.

HashMap :

SortedMap :

TreeMap:

They will give one String

String str = “sdfhsfhsdkfjhsjfhkj”;

String is characterArray.

Str.toCharArray();

Which character is the highest repeated character in this string.

import java.util.HashMap;

import java.util.Map;

class StringPrg {

public static void main(String args[]){

String str= "sfdfsdfsdfsfdasa";

Map<Character,Integer> map1 = new HashMap<Character,Integer>();

for(int k=0; k < str.length(); k++)

char currentChar = str.charAt(k);

//to check that currentChar is not in map, if not will add 1 count for firsttime

if(map1.get(currentChar) == null){
map1.put(currentChar, 1);

/*If it is repeating then simply we will increase the count of that key(character) by 1*/

else {

map1.put(currentChar, map1.get(currentChar) + 1);

//Now To find the highest character repeated

int max=0;

char maxCharacter = 'a';//setting to a by default

for (Map.Entry<Character, Integer> entry : map1.entrySet())

System.out.println("Key=" + entry.getKey() + ":Value" + entry.getValue());

if(max<entry.getValue()){

max=entry.getValue();

maxCharacter=entry.getKey();

System.out.println("Max Character=" + maxCharacter + "Max Count" + max);

Java 8: Concepts:

Functional Interface: it should only one abstract method.

Lambda Expressions: Implementation of functional interfaces.

 {

MethodReferences:

Streams :

DateTime:

ErrorHandling:

You might also like