본문 바로가기
자바

Java에서 toString 메서드를 사용하는 방법은 무엇입니까?

by º기록 2021. 4. 13.
반응형

객체 클래스에 정의 된 tostring () 메소드의 개념을 설명 할 수 있습니까?그것이 어떻게 사용됩니까? 그리고 그 목적은 무엇입니까?

 

해결 방법

 


그 문자열 표현을 반환합니다 object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses 이 방법을 재정의하십시오.

객체 클래스의 tostring 메소드 returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value 의:

getClass().getName() + '@' + Integer.toHexString(hashCode())

예:

String[] mystr ={"a","b","c"};
System.out.println("mystr.toString: " + mystr.toString());

output:- mystr.toString: [Ljava.lang.String;@13aaa14a

 

참조 페이지 https://stackoverflow.com/questions/3615721

 

 

반응형

댓글