개요
- Java 문자열을 다뤄본다.
Java
Copy
public class MyClass {
public static void main(String args[]) {
String greetings = "Hello World";
//문자열의 길이 확인하기
String txt1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.println("The length of the txt1 string is: " + txt1.length());
//대문자 전환, 소문자전환
String txt2 = "Hello World";
System.out.println(txt2.toUpperCase()); // Outputs "HELLO WORLD"
System.out.println(txt2.toLowerCase()); // Outputs "hello world"
//문자열내에서 문자열 찾기
String txt3 = "Please locate where 'locate' occurs!";
System.out.println(txt3.indexOf("locate")); // Outputs 7
String firstName = "John";
String lastName = "Doe";
//문자열 붙이는 방법 1
System.out.println(firstName + lastName);
//문자열 붙이는 방법 2
System.out.println(firstName.concat(lastName));
}
}
⚠️
편집자 에어컨 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.