Java ForEach

1 개요[ | ]

Java Foreach

2 Array[ | ]

public class MyClass {
	public static void main(String[] args) {
		String[] strArr = { "John Smith", "Jane Doe", "Mike Barnes", "Kevin Patterson" };
		for (String str : strArr){
			System.out.println(str);
		}
	}
}

3 HashMap[ | ]

import java.util.HashMap;
import java.util.Map;

public class MyClass {
	public static void main(String[] args) {
		HashMap<String,Object> member = new HashMap<String,Object>();
		member.put("ID", "102");
		member.put("Name", "YONEZAWA Akinori");
		member.put("Address", "Naha, Okinawa");

		for(Map.Entry<String, Object> m:member.entrySet()) {
			System.out.println( "KEY:" + m.getKey()+", VALUE="+m.getValue() ); 
		}
	}
}
import java.util.HashMap;
import java.util.Map;

public class MyClass {
	public static void main(String[] args) {
		HashMap<String,Object> member = new HashMap<String,Object>();
		member.put("ID", "102");
		member.put("Name", "YONEZAWA Akinori");
		member.put("Address", "Naha, Okinawa");

		member.forEach((key, value) -> {
			System.out.println( "KEY:" + key+", VALUE="+value ); 
		});
	}
}

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}