"Java 문자열"의 두 판 사이의 차이

2번째 줄: 2번째 줄:
;Java 문자열을 다뤄본다.
;Java 문자열을 다뤄본다.
<syntaxhighlight lang="java" run>
<syntaxhighlight lang="java" run>
public class HelloWorld {
public class Main{
     public static void main(String[] args){
     public static void main(String[] args){
         String greetings = "Hello World";
         String greetings = "Hello World";

2021년 8월 22일 (일) 17:41 판

개요

Java 문자열을 다뤄본다.
Java
Copy
public class Main{
    public static void main(String[] args){
         String greetings = "Hello World";

         //문자열의 길이 확인하기
         String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         System.out.println("The length of the txt string is: " + txt.length());

         //대문자 전환, 소문자줜환
         String txt = "Hello World";
         System.out.println(txt.toUpperCase());   // Outputs "HELLO WORLD"
         System.out.println(txt.toLowerCase());   // Outputs "hello world"

         //문자열내에서 문자열 찾기
         String txt = "Please locate where 'locate' occurs!";
         System.out.println(txt.indexOf("locate")); // Outputs 7

         //문자열 붙이는 방법 1
         String firstName = "John";
         String lastName = "Doe";
         System.out.println(firstName + " " + lastName);

         //문자열 붙이는 방법 2
         String firstName = "John ";
         String lastName = "Doe";
         System.out.println(firstName.concat(lastName));



    }
}
⚠️
편집자 에어컨 J Jmnote