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
	}
}