import java.util.Arrays;
public class TestArrays {
public static void main(String[] args) {
int[] a= {6,2,1,4,5,8,3};
System.out.println(a);
System.out.println(Arrays.toString(a));
Arrays.sort(a);
System.out.println(Arrays.toString(a));
System.out.println(Arrays.binarySearch(a, 4));
}
}
上述输出:
[I@279f2327
[6, 2, 1, 4, 5, 8, 3]
[1, 2, 3, 4, 5, 6, 8]
3
import java.util.Arrays;
public class Test2DimensionArray {
public static void main(String[] args) {
int [][] a=new int[3][];
a[0]= new int[] {20,30};
a[1]=new int[] {10,15,60};
a[2]=new int[] {50,60};
System.out.println(a[1][2]);
}
}
import java.util.Arrays;
public class TeatArrayTableData {
public static void main(String[] args) {
Object[] emp1= {1001,"柴大",19,"学生"};
Object[] emp2= {1002,"柴二",22,"销售"};
Object[] emp3= {1003,"柴三",24,"讲师"};
Object[][] tableData=new Object[3][];
tableData[0]=emp1;
tableData[1]=emp2;
tableData[2]=emp3;
for(Object[] temp:tableData) {
System.out.println(Arrays.toString(temp));
}
}
}
import java.util.Arrays;
public class TeatBubbleSort {
public static void main(String[] args) {
int[] values= {3,1,6,2,9,7,0,4,8};
for(int i=0;i<values.length;i++) {
int temp=0;
boolean flag=true;
for(int j=0;j<values.length-1-i;j++) {
if(values[j]>values[j+1]) {
temp=values[j+1];
values[j+1]=values[j];
values[j]=temp;
flag=false;
}
}
if(flag) {
System.out.println(Arrays.toString(values));
break;
}
}
}
}
import java.util.Arrays;
public class TestBinarySearch {
public static void main(String[] args) {
int[] arr= {2,5,8,44,33,30,20,60,50,80,70,110,40};
Arrays.sort(arr);
int value=40;
System.out.println(Arrays.toString(arr));
System.out.println(myBinarySearch(arr, value));
}
public static int myBinarySearch(int[] arr,int value){
int low=0;
int high=arr.length-1;
while(low<=high) {
int mid=(low+high)/2;
if(value==arr[mid]) {
return mid;
}
if(value<arr[mid]) {
high=mid-1;
}
if(value>arr[mid]) {
low=mid+1;
}
}
return -1;
}
}
public class TestWrappedClass{
public static void main(String[] args) {
Integer a=new Integer(33);
Integer b=Integer.valueOf(30);
int c=b.intValue();
double d=b.doubleValue();
Integer e=new Integer("9999");
Integer f=Integer.parseInt("999");
String str=f.toString();
}
}
public class TestAutoBox {
public static void main(String[] args) {
Integer a=234;
int b=a;
}
}
public class TestStringBuilder{
public static void main(String[] args) {
StringBuilder sb=new StringBuilder("abcdefg");
System.out.println(Integer.toHexString(sb.hashCode()));
System.out.println(sb);
sb.setCharAt(3, 'H');
System.out.println(Integer.toHexString(sb.hashCode()));
System.out.println(sb);
}
}