Java反转数组的两种方法

第一种:

String[] array = new String[] {"aa","bb","cc"};
    	
    	for(int i = 0; i < array.length/2;i++) {
    		String temp = array[i];
    		array[i] = array[array.length -i -1];
    		array[array.length -i -1] = temp;
    	}

第二种

        String[] array = new String[] {"aa","bb","cc"};
        for(int i=0,j=array.length-1;i<j;i++,j--) {
    		String temp = array[i];
    		array[i] = array[j];
    		array[j] = temp;
    	}

你可能感兴趣的:(笔记,java,eclipse,spring,java-ee)