Java: split() returns [Ljava.lang.String;@186d4c1], why?

后端 未结 3 1391
陌清茗
陌清茗 2020-12-18 12:04

And i have no idea why!

I bascially have a STRING (yes, not an array), that has the following contents:

[something, something else, somoething, trall         


        
相关标签:
3条回答
  • 2020-12-18 12:22

    You are getting a valid array of Strings, but trying to print it directly does not do what you would expect it to do. Try e.g.

    System.out.println(Arrays.asList(urlArr));
    

    Update

    If you want to process the parsed tokens one by one, you can simply iterate through the array, e.g.

    for (String url : urlArr) {
      // Do something with the URL, e.g. print it separately
      System.out.println("Found URL " + url);
    }
    
    0 讨论(0)
  • 2020-12-18 12:25

    When you do toString on an Array, you just get the internal representation. Not that useful. Try Arrays.toString(what comes back from split) for something more readable.

    0 讨论(0)
  • 2020-12-18 12:43

    The output

    [Ljava.lang.String;@186d4c1
    

    is the way java prints a string array (or any array) by default (when converted to a string). You may use

    Arrays.toString(urlArr)
    

    to get a more readable version.

    0 讨论(0)
提交回复
热议问题