Java: Converting a set to an array for String representation

前端 未结 6 999
遇见更好的自我
遇见更好的自我 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条回答
  •  终归单人心
    2021-02-05 02:48

    I don't think you have misunderstood anything; the code should work. The array, however, is not smart enough to print its contents in the toString method, so you'll have to print the contents with

    for(String s : array) println(s);
    

    or something like that.

提交回复
热议问题