Java的:转换一套为字符串数组重新presentation [英] Java: Converting a set to an array for String representation
本文介绍了Java的:转换一套为字符串数组重新presentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从Sun的 Java教程,我还以为这$ C $ ç将一组转换为数组。
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 main(String[] args) {
Set<String> set = new HashSet<String>();
set.add("a");
set.add("b");
set.add("c");
String[] array = set.toArray(new String[0]);
System.out.println(set);
System.out.println(array);
}
}
然而,这给
[a, c, b]
[Ljava.lang.String;@9b49e6
我有什么误解?
推荐答案
在code正常工作。
替换为:
System.out.println(array);
使用:
System.out.println(Arrays.toString(array));
输出:
[b, c, a]
[b, c, a]
的字符串
重数组的presentation显示一个数组的文本重新presentation,由<一个获得href=\"http://java.sun.com/javase/6/docs/api/java/lang/Object.html#toString%28%29\"><$c$c>Object.toString$c$c> - 这是类名和数组作为十六进制字符串的哈希值code
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.
这篇关于Java的:转换一套为字符串数组重新presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文