Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210312] (Java) Arrays toString(), deepToString(), instanceof, isInstance(), char to int #65

Open
JuHyun419 opened this issue Mar 12, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

JuHyun419 commented Mar 12, 2021

Arrays toString(), deepToString()

  • 1차원 배열 값 출력할때 for문 사용했었는데, toString()으로 바로 출력
  • deepToString -> 2차원 배열 이상 출력
import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        System.out.println(Arrays.toString(arr));

        int[][] arr2 = {{1, 2}, {3, 4, 5}};
        System.out.println("toString: " + Arrays.toString(arr2));
        System.out.println("deepToString: " + Arrays.deepToString(arr2));

        int[][][] arr3 = {{{1, 2}, {3, 4, 5}}};
        System.out.println(Arrays.deepToString(arr3));
    }
}

[1, 2, 3, 4, 5]
toString: [[I@5d5eef3d, [I@56f4468b, [I@6cc4c815]
deepToString: [[1, 2], [3, 4, 5]]
deepToString: [[[1, 2], [3, 4, 5]]]


instanceof vs isInstance()

  • instanceof : 컴파일시 타입 체크
  • isInstance(): 런타임시 타입 체크

## char to int - char - '0'
        char ch = '1';
        char ch2 = '9';
        System.out.println(ch - '0');
        System.out.println(ch2 - '0');

1
9

@JuHyun419 JuHyun419 added the Java label Mar 12, 2021
@JuHyun419 JuHyun419 changed the title [20210312] Arrays toString(), deepToString(), instanceof, isInstance() [20210312] (Java) Arrays toString(), deepToString(), instanceof, isInstance(), char to int Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant