在java.util包中,有一个用于操作数组的实用类:java.util.Arrays.它提供了一系列静态方法。具体见javaAPI
package package14_7; import java.util.Arrays; public class Array_2 { public static void testStringArray(){ String[] s1={"Tom","Jack","Mike","Tom2"}; String[] s2={"Tom","Jack","Mike","Tom2"}; System.out.println("s1和s2比较"+Arrays.equals(s1, s2));//true Arrays.sort(s1);//为数组S1排序 System.out.println("s1和s2二次比较"+Arrays.equals(s1, s2)); //false System.out.println("Jack在S1数组中位置"+Arrays.binarySearch(s1, "Jack")); System.out.println("Jack在S2数组中位置"+Arrays.binarySearch(s2, "Jack")); System.out.println("s1"+Arrays.toString(s1)); } public static void main(String[] args) { testStringArray(); } }
s1和s2比较true
s1和s2二次比较false
Jack在S1数组中位置0
Jack在S2数组中位置1
s1[Jack, Mike, Tom, Tom2]