本文主要是介绍Tiger学习 之 Arrarys,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
toString方法:直接输出数组的各个元素的值[quote]
String[] str1 = {"a","b","c"} ;
System.out.println("str1 values are : "+Arrays.toString(str1));
输出:str1 values are : [a, b, c]
[/quote]
deepToString方法:直接输出多维数组的各个元素的值
[quote]
String[][] str2 = {{"a","aa"},{"b","bb"},{"c","cc"}};
System.out.println("str2 values are: "+Arrays.deepToString(str2));
输出:str2 values are: [[a, aa], [b, bb], [c, cc]]
[/quote]
equals方法:比较两个数组的值是否相等
[quote]
String[] str1 = {"a","b","c"} ;
String[] str2 = {"a","b","c"} ;
if (Arrays.equals(str1, str2))
System.out.println("str1 and str2 are equal.");
else
System.out.println("str1 and str2 are not equal.");
输出:str1 and str2 are equal.
[/quote]
deepEquals方法:比较两个多维数组的值是否相等
[quote]
String[][] str1 = {{"a","aa"},{"b","bb"},{"c","cc"}};
String[][] str2 = str1.clone();
if (Arrays.deepEquals(str1, str2))
System.out.println("str1 and str2 are equal.");
else
System.out.println("str1 and str2 are not equal.");
输出:str1 and str2 are equal.
[/quote]
fill方法:一维数组的填值
[quote]
String[] str1 = new String[2];
Arrays.fill(str1, "{abc}");
System.out.println("str1 values are: "+Arrays.toString(str1));
输出:str1 values are: [{abc}, {abc}]
[/quote]
hashCode,deepHashCode 方法:取得数组的hashCode和deepHashCode值。
sort 方法:对数组元素进行排序
这篇关于Tiger学习 之 Arrarys的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!