問答題java
A:String的特色: 一旦被建立就不能改變 B:案例演示 a:如何理解這句話 String s = "hello" ; s = "world" + "java"; 問s的結果是多少? 下面這條語句一共建立了多少個對象:String s = 「a」+「b」+」c」; 分別都是什麼? 答案:5個對象 分別是 "a" , "b" , "c" , "ab" , "abc" 由於字符串的特色是一旦被建立就不能被改變,全部在使用常量進行相加的時候,都是在建立新的字符串對象 最後在把字符串"abc"這個常量值賦值給引用變量s
輸出結果: 正則表達式
A:String -- StringBuffer數組
B:StringBuffer -- String安全
冒泡排序原理架構
/** * 冒泡排序 * @param arr */ private static void bubbleSort(int[] arr) { for(int y = 0 ; y < arr.length - 1; y++) { for(int x = 0 ; x < arr.length - 1 - y ; x++ ) { if(arr[x] > arr[x+1]) { int temp = arr[x] ; arr[x] = arr[x+1] ; arr[x+1] = temp ; } } } }
選擇排序原理app
數組高級選擇排序代碼實現dom
private static void selectSort(int[] arr) { for(int index = 0 ; index < arr.length - 1 ; index++) { for(int x = index + 1 ; x < arr.length ; x++) { if(arr[index] > arr[x]) { int temp = arr[index] ; arr[index] = arr[x] ; arr[x] = temp ; } } } }
數組高級二分查找思想ide
數組高級二分查找代碼函數
/** * 二分查找 * @param arr * @return */ private static int binarySearch2(int[] arr , int value) { // 定義三個變量 int minIndex = 0 ; int maxIndex = arr.length - 1 ; while(minIndex <= maxIndex) { int midIndex = (minIndex + maxIndex) >>> 1 ; // 比較 if(arr[midIndex] == value) { return midIndex ; }else if(arr[midIndex] > value) { maxIndex = midIndex - 1 ; }else if(arr[midIndex] < value) { minIndex = midIndex + 1 ; } } // 返回 return -1; }
爲了對基本數據類型進行更多的操做,更方便的操做,java就針對每一種基本數據類型提供了對應的類類型.測試
經常使用的操做之一:用於基本數據類型與字符串之間的轉換
byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean
正則表達式,不須要記憶,用的時候去查就能夠呢
* 正則的獲取功能須要使用的類
* Math 類包含用於執行基本數學運算的方法,如初等指數、對數、平方根和三角函數。 * 成員變量
public static final double E : 天然底數 public static final double PI: 圓周率 * 成員方法 public static int abs(int a) 取絕對值 public static double ceil(double a) 向上取整 public static double floor(double a) 向下取整 public static int max(int a,int b) 獲取最大值 public static int min(int a, int b) 獲取最小值 public static double pow(double a,double b)獲取a的b次冪 public static double random() 獲取隨機數 返回帶正號的 double 值,該值大於等於 0.0 且小於 1.0。 public static int round(float a) 四捨五入 public static double sqrt(double a) 獲取正平方根
隨機類
public Random() 沒有給定種子,使用的是默認的(當前系統的毫秒值) public Random(long seed) 給定一個long類型的種子,給定之後每一次生成的隨機數是相同的 public int nextInt() public int nextInt(int n)
系統級類