Pitch your project

Random text


By admin Category Uncategorized, Posted March 18th, 2016
HashMap in Java

HashMap maintains key and value and often denoted as HashMap or HashMap. HashMap implements Map interface. HashMap is similar to Hashtable with two exceptions HashMap methods are unsynchronized and it allows null key and null values unlike Hashtables it is used for maintaining key and values mapping

It is not an ordered collection which means it does not return the key and values in the same order in which they have been inserted into the HashMap. It neither does any kind of sorting to the stored keys and values. You must need to import java util.HashMap or its super class in order to use the HashMap class and methods.

HashMap example

Example 1:
public Map<string , Integer> getAvAndRes(String course_name, String group_name) {
        HashMap</string><string ,Integer> avAndRes = new HashMap<>();
   List<coursegroup> courseGroups = server.find(CourseGroup.class).where().like("course_name" , course_name).like("group_name", group_name).findList();
    if(courseGroups == null ) throw new NotFoundException("Course and Group not found");
    CourseGroup courseGroup = courseGroups.get(0);
    int availableSeats = courseGroup.getAvailable_seats();
    int reservedSeats = courseGroup.getSeats() - availableSeats;
    return avAndRes;
Example 2:
public Set<string> getGroups(String course_name) {
        HashSet</string><string> groupNames = new HashSet();
        List<coursegroup> courseGroups= server.find(CourseGroup.class).where().like("course_name", course_name).findList();
        if(courseGroups==null) throw new NotFoundException("The coursename does not exist");
        for(CourseGroup cg : courseGroups) {
            String groupname=cg.getGroup_name();
        return groupNames;

Posted by David Mirieri

Leave a Reply

Your email address will not be published. Required fields are marked *