Category: Collections

java tutorials

Initialization of an ArrayList in one line example

This tutorials demonstrates how to initialize a list or arraylist in one line in different ways. The traditional way to create and initialize an ArrayList is: List<String> planets = new ArrayList<String>(); planets.add(“Earth”); planets.add(“Mars”); planets.add(“Venus”);...
java tutorials

Different Ways to Iterate over a Map in Java

Map<k, v> A Map has Set of key value pairs. One key refers to only one value as such a map cannot contain duplicate keys. package com.memorynotfound.collections.map; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * @author MemoryNotFound.com...
java tutorials

Different Ways to Iterate over a Set in Java

Iterate over a Set A Set is a Collection that cares about uniqueness, it doesn’t allow duplicate elements. The .equals() method determines whether two objects are identical in witch case only one object can be...