JAVA를 JAVA라

[JAVA] MessageFormat 본문

JAVA/함수 (eclipse)

[JAVA] MessageFormat

샛별KIM 2021. 5. 31. 11:18
import java.text.MessageFormat;

public class TestFormat01 {
	public static void main(String[] args) {
		System.out.printf("%d", 3); 
		
		String name = "홍길동";
		String id = "hong5000";
		String tel = "010-0123-0123";
		
		System.out.println("이름 : " + name + " 아이디 : " + id + " tel : " + tel);
		
		String text = "이름 : {0}, 아이디 : {1}, tel : {2}";
		
		String result = MessageFormat.format(text, name, id, tel);
		System.out.println(result);
		//이름 : 홍길동, 아이디 : hong5000, tel : 010-0123-0123
		
		String[] arr = {"홍길동", "hong5000", "010-0123-0123"};
		result = MessageFormat.format(text, arr);
		System.out.println(result);
		//이름 : 홍길동, 아이디 : hong5000, tel : 010-5569-8102
	}
}

'JAVA > 함수 (eclipse)' 카테고리의 다른 글

[JAVA] substring(x, y)  (0) 2021.06.03
[JAVA] ...is, 무한 플러스 계산기  (0) 2021.06.02
[JAVA] Date, SimpleDateFormat  (0) 2021.05.31
[JAVA] printf 출력문 참고  (0) 2021.05.31
[JAVA] .split  (0) 2021.05.28
Comments