개발
자바 문자열
JK.
2022. 1. 28. 10:41
728x90
- 문자열 길이
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt string is: " + txt.length());
:: The length of the txt string is: 26
- 대소문자 변환
String txt = "Hello World";
System.out.println(txt.toUpperCase());
System.out.println(txt.toLowerCase());
:: HELLO WORLD
:: hello world
- 문자열 찾기
String txt = "Please locate where 'locate' occurs!";
System.out.println(txt.indexOf("locate"));
:: 7
- 문자열 연결
String firstName = "John";
String lastName = "Doe";
System.out.println(firstName + " " + lastName);
:: John Doe
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName
:: John Doe
- 특수문자
String txt = "We are the so-called \"Vikings\" from the north.";
System.out.println(txt);
:: We are the so-called "Vikings" from the north.
String txt = "It\'s alright.";
System.out.println(txt);
:: It's alright.
String txt = "The character \\ is called backslash.";
System.out.println(txt);
:: The character \ is called backslash.