Java: Converting a set to an array for String representation

前端 未结 6 987
遇见更好的自我
遇见更好的自我 2021-02-05 02:08

From Sun\'s Java Tutorial, I would have thought this code would convert a set into an array.

import java.util.*;

public class Blagh {
    public static void mai         


        
6条回答
  •  梦毁少年i
    2021-02-05 02:57

    The code works fine.

    Replace:

    System.out.println(array);
    

    With:

    System.out.println(Arrays.toString(array));
    

    Output:

    [b, c, a]
    [b, c, a]
    

    The String representation of an array displays the a "textual representation" of the array, obtained by Object.toString -- which is the class name and the hash code of the array as a hexidecimal string.

提交回复
热议问题