Java. In a loop, output the key and value of the Map at the same time

//In a loop, output key and value at the same time
	public static void main(String[] args) {
		Map<String, String> hashMap = new HashMap<String, String>();
		hashMap.put("a", "1234");
		hashMap.put("m", "oi");
		hashMap.put("p", "看");
		hashMap.put("d", "fuck");
		hashMap.put("e", "2");
		hashMap.put("v", "-_-");//Above, add elements

		//Change the Map interface to the Set interface
		Set<Entry<String, String>> entrySet = hashMap.entrySet();
		//get Iterator
		Iterator<Entry<String, String>> iterator = entrySet.iterator();
		
		// simultaneously output key and value
		while (iterator.hasNext()) {
			//Get key and value through iterator.next()
			Entry<String, String> next = iterator.next();
			System.out.println(next.getKey() + " -> " + next.getValue());
		}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326985579&siteId=291194637