Java 문자열

Jmnote (토론 | 기여)님의 2021년 8월 22일 (일) 18:43 판 (→‎개요)

개요

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));
    }
}
⚠️