less than 1 minute read

Concat 함수

Concat 은 Object method 로 string 을 이어 주는 역할을 한다

public class String test {
  public static void main(String[] args)
  {
    String firstStr = new String("hello");
    String secondStr = new String("world");
    
    System.out.println(firstStr);
    System.out.println(System.identifyHashCode(firstStr);
    
    firstStr = firstStr.concat(secondStr);
    System.out.println(firstStr);
    System.out.println(System.identifyHashCode(firstStr);
  }
}

값은

hello
254621641

helloworld
266210221

같은 firstStr 프린트했지만
concat 을 이용해서 문자열을 붙이고 나면 변경이 아니라 새로 생성된다

Categories:

Updated: