HashMap in Python, Java, Typescript and Go

 Python

In Python Map/Hashmap is implemented as dictionaries,  the dictionaries have items stored as key-value pairs, where keys should be unique. 

single_dict = dict(roleId=10001,name='Test')
print(single_dict)

multi_dict = []
single_dict_1 = {'roleId':10001,'name':'Test'}
single_dict_2 = {'roleId':10002, 'name':'Test1'}
multi_dict.append(single_dict_1)
multi_dict.append(single_dict_2)

print(multi_dict)


Java

Map

public class Main {
    public static void main(String args[]) {
      Map<String, SchoolClass> mapTemp = new HashMap();
      SchoolClass klass1 = new SchoolClass(10001, "Test");
      SchoolClass klass2 = new SchoolClass(10002, "Test1");
      
      
      mapTemp.put("klass1", klass1);
      mapTemp.put("klass2", klass2);
          
      mapTemp.forEach((k, v) -> System.out.println((k + ":" + v)));
    }
}

public class SchoolClass{
    
    public SchoolClass(Integer id, String name){
        this.roleId = id;
        this.name = name;
    }
    Integer roleId;
    String name;
    
    public String toString(){
        return "RoleId: "+this.roleId+ " Name: "+ this.name;
    }
}

Comments

Popular posts from this blog

AWS S3 MRAP

SLO Compliance