How do I declare an array?

Asked 2 years ago, Updated 2 years ago, 88 views

How do I declare the arrangement?

java array

2022-09-22 22:37

1 Answers

There are many ways to do it. It depends on the data type.

    int[] myIntArray = new int[3];
    int[] myIntArray = {1,2,3};
    int[] myIntArray = new int[]{1,2,3};

It's the most basic form, and the string class is the same.

    String[] myStringArray = new String[3];
    String[] myStringArray = {"a","b","c"};
    String[] myStringArray = new String[]{"a","b","c"};

You can do it like this.


2022-09-22 22:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.