/** * @author lautturi.com * Java example:Converting map to string in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(5, "Apple"); map.put(7, "banana"); map.put(1, "Cherry"); map.put(33, "Orange"); map.put(23, "Lautturi"); String mapStr = map.toString(); System.out.println("Map: " + map); System.out.println("Map to String: " + mapStr); } }
output:
Map: {1=Cherry, 33=Orange, 5=Apple, 7=banana, 23=Lautturi} Map to String: {1=Cherry, 33=Orange, 5=Apple, 7=banana, 23=Lautturi}