본문 바로가기
개발일지/수업내용

210810(화)_DAY 15 (String 메소드)

by jungwonyu 2021. 8. 10.

[문자열을 대문자로 바꿔주는 메소드] java.lang > String > toUpperCase 

Converts all of the characters in this String to upper case using the rules of the default locale.

This method is equivalent to toUpperCase(Locale.getDefault()).

	public static void main(String[] args) {

		String str = "The String class represents character strings.";
		String res = str.toUpperCase();
		System.out.println(res);
	}
▶Console
THE STRING CLASS REPRESENTS CHARACTER STRINGS.

 

[문자열을 소문자로 바꿔주는 메소드] java.lang > String > toLowerCase

Converts all of the characters in this String to lower case using the rules of the default locale.

This is equivalent to calling toLowerCase(Locale.getDefault()).

	public static void main(String[] args) {

		String str = "The String class represents character strings.";
		String res = str.toLowerCase();
		System.out.println(res);
	}
▶Console
the string class represents character strings.

 

[문자열을 대체하는 메소드] java.lang > String > replace

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

	public static void main(String[] args) {

		String str = "The String class represents character strings.";
		String res = str.replace("character", "String");
		System.out.println(res);
	}
▶Console
The String class represents String strings.