Print HashMap values ​​(these values ​​are arrays)

I try and look for questions that are similar to mine for almost 2 days, I hope that I find out the answer, but no, I couldn’t, I decided to ask you guys here.

This method is designed to print all keys and values HashMap<String, int[]> ratingmap. So, keys String, and values ​​are arrays. I worked on this, and below is my code.

public void showRatingsMap() {
    for (String customer: ratingmap.keySet()) {
        String key = customer.toString();
        int[] value = ratingmap.get(key);
        System.out.println("Customer: " + key + " - Rating: " + value);
    }
}

I am really confused at the moment, because the printed result is as follows:

Customer: Douglas Anderson - Rating: [I@4f5b571e
Customer: Sidney - Rating: [I@75b49b45
Customer: Apollo - Rating: [I@243e0b62
Customer: Leslie - Rating: [I@655d6184

Since I expect the rating to be an array, but it always looks like a weird combination above: [I @ 2b9fd66a

Can someone point out errors that cause the problem?

+3
source share
4 answers

- "int []", ints. , . , , .

, . :

for (int v : value) {
    System.out.println(v);
}

, ( , )

+2

, , toString - " " [I "" , , @75b49b45, per- JVM.

:

    int array[] = new int[] {3, 1, 4, 1};
    for (int i : array)
        System.out.print(i + " ");
    System.out.println();

List, toString():

    int array[] = new int[] {3, 1, 4, 1};
    List<Integer> asList = new ArrayList<Integer>();

    for (int i : array)
        asList.add(i);
    System.out.println(asList);

, , [I - , toString, toString() Object, , @, . - [I.

. javadoc Class#getName() JDK.

+1

- HashMap<String, List<Integer>>, , .

+1

All Articles