1.1 Scanner類
1.1.1構造方法
public Scanner(InputStream source)
1.1.2 成員方法
public int nextInt() : 從鍵盤輸入一個整數
public String nextLine() :從鍵盤輸入一串字符串
public String next() : 從鍵盤輸入一個字符串
區別 :https://blog.csdn.net/tuke_tuke/article/details/51330086
1.2 String類
1.2.1 構造方法
•public String()
•public String(byte[] bytes)
•public String(byte[] bytes, intoffset, intlength)
•public String(char[] value)
•public String(char[] value, intoffset, intcount)
•public String(String original)
1.2.2 成員方法-----字符串判斷功能
boolean equals(Object obj) :將此字符串與指定的對象比較
boolean equalsIgnoreCase(String str) :將此
String
與另一個 String
比較,不考慮大小寫。boolean contains(String str) : 當且僅當此字符串包含指定的 char 值序列時,返回 true。
boolean startsWith(String str) : 測試此字符串是否以指定的前綴開始。
boolean endsWith(String str) : 測試此字符串是否以指定的後綴結束。
boolean isEmpty() : 判斷字符串是否爲空
1.2.3 成員方法-----字符串獲取功能
int length() :字符串的長度
char charAt(int index) : 返回指定索引處的
char
值int indexOf(int ch) :返回指定字符在此字符串中第一次出現處的索引
int indexOf(String str) :返回指定子字符串在此字符串中第一次出現處的索引。
int indexOf(int ch, int fromIndex) :返回指定字符在此字符串中第一次出現處的索引,從指定的索引開始。
int indexOf(String str, int fromIndex):返回指定子字符串在此字符串中第一次出現處的索引,從指定的索引開始。
String substring(int start) :返回一個新的字符串,它是此字符串的一個子字符串
String substring(int start, int end) : 返回一個新字符串,它是此字符串的一個子字符串
1.2.3 成員方法-----字符串轉換功能
byte[] getBytes(): 把字符串轉化爲字節數組
char[] toCharArray():把字符串轉化爲字符數組
static String valueOf(char[] chs): 將 char 數組 chs 轉換成字符串
static String valueOf(int i): 將整形i轉換成數組
String toLowerCase():
String
中的所有字符都轉換爲小寫String toUpperCase():
String
中的所有字符都轉換爲大寫String concat(String str):將指定字符串連接到此字符串的結尾
1.2.4 成員方法-----字符串替換功能
1.2.4.1替換功能
•String replace(char old,char new):
•String replace(String old,String new):
1.2.4.2去除字符串兩空格
•String trim(): 返回字符串的副本,忽略前導空白和尾部空白
1.2.4.3按字典順序比較兩個字符串
•int compareTo(String str):比較兩個字符串
•int compareToIgnoreCase(String str) : 忽略大小寫比較兩個字符串
1.3 StringBuffer
1.3.1 構造方法
public StringBuffer()
public StringBuffer(int capacity)
public StringBuffer(String str)
1.3.2 成員方法
1.3.2.1添加功能
•public StringBuffer append(String str): 將指定的字符串追加到此字符序列
•public StringBuffer insert(char[] str): 將
char
數組參數的字符串表示形式追加到此序列。1.3.2.2刪除功能
•public StringBuffer deleteCharAt(int index): 移除此序列指定位置的
char
•public StringBuffer delete(int start,int end): 移除此序列的子字符串中的字符。
1.3.2.3替換功能
•public StringBuffer replace(int start,int end,String str): 使用給定
String
中的字符替換此序列的子字符串中的字符1.3.2.4反轉功能
public StringBuffer reverse(): 將此字符序列用其反轉形式取代
1.3.2.5截取功能
•public String substring(int start) : 返回一個新的
String
,它包含此字符序列當前所包含的字符子序列•public String substring(int start, int end): 返回一個新的
String
,它包含此序列當前所包含的字符子序列。該子字符串從指定 的 start
處開始,一直到索引 end - 1
處的字符lString,StringBuffer,StringBuilder的區別: https://www.cnblogs.com/su-feng/p/6659064.html
1.4 Arrays類
1.4.1成員方法
•public static String toString(int[] a) :返回指定數組內容的字符串表示形式
•public static void sort(int[] a): 制定數組排序
•public static int binarySearch(int[] a, int key):使用二分搜索法來搜索指定的 int 型數組,以獲得指定的值
1.5 Interger類
1.5.1構造方法
•public Integer(int value): 構造一個新分配的
Integer
對象,它表示指定的 int
值。 •public Integer(String s):構造一個新分配的
Integer
對象,它表示 String
參數所指示的 int
值1.5.2成員方法
public int intValue(): 以
int
類型返回該 Integer
的值。public static int parseInt(String s):將字符串參數作爲有符號的十進制整數進行解析
public static String toString(int i):返回一個表示指定整數的
String
對象public static Integer valueOf(int i):返回一個表示指定的 int 值的 Integer 實例
public static Integer valueOf(String s): 返回保存指定的
String
的值的 Integer
對象。1.5.3 常用的基本進制轉換
•public static String toBinaryString(int i):十轉二
•public static String toOctalString(int i) :十轉八
public static String toHexString(int i): 十轉十六1.5.4十進制到其他進制
•public static String toString(int i, int radix): 參數:
i
- 要轉換成字符串的整數。 radix
- 用於字符串表示形式的基數1.5.5其他進制到十進制
•public static int parseInt(String s, int radix):
參數:
s
- 包含要解析的整數表示形式的 String
radix
- 解析 s
時使用的基數。1.6 Character類
1.6.1構造方法
•public Character(char value)
1.6.2成員方法
public static boolean isUpperCase(char ch):確定指定字符串是否爲大寫
public static boolean isLowerCase(char ch):確定指定字符串是否爲小寫
public static boolean isDigit(char ch):確定指定字符是否爲數字。
public static char toUpperCase(char ch):把字符串變成大寫
public static char toLowerCase(char ch):把字符串變成小寫
1.7 正則表達式
判斷功能
•public boolean matches(String regex)
分割功能
•public String[] split(String regex)
替換功能
•public String replaceAll(String regex,String replacement)
獲取功能
•Pattern和Matcher類的使用
1.8Math類
1.8.1成員方法
•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) min自學
•public static double pow(double a,double b)
•public static double random()
•public static int round(float a) 參數爲double的自學
•public static double sqrt(double a)
1.9Random類
1.9.1構造方法
•public Random()
•public Random(long seed)
1.9.2 成員方法
public int nextInt()
public int nextInt(int n)
1.10 System類
•System 類包含一些有用的類字段和方法。它不能被實例化。
1.10.1成員方法
•public static void gc() :垃圾回收
•public static void exit(int status)
•public static long currentTimeMillis()
•public static void arraycopy(Object src,int srcPos,Object dest,int dest Pos,int length)
1.11 BigInteger類
可以讓超過Integer範圍內的數據進行運算
1.11.1構造方法
•public BigInteger(String val)
1.11.2 成員方法
public BigInteger add(BigInteger val)
public BigInteger subtract(BigInteger val)
public BigInteger multiply(BigInteger val)
public BigInteger divide(BigInteger val)
public BigInteger [] divideAndRemainder(BigInteger val)
1.12 BigDecimal類
由於在運算的時候,float類型和double很容易丟失精度,演示案例。所以,爲了能精確的表示、計算浮點數,Java提供了BigDecimal
1.12.1構造方法
•public BigDecimal(String val)
1.12.2成員方法
public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor)
public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode)
1.13 Date類
•類 Date 表示特定的瞬間,精確到毫秒。
1.13.1構造方法
•public Date()
•public Date(long date)
1.13.2成員方法
•public long getTime()
•public void setTime(longt ime)
1.14 DateFormate類
•DateFormat是日期/時間格式化子類的抽象類,它以與語言無關的方式格式化並解析日期或時間。
•是抽象類,所以使用其子類SimpleDateFormat
1.14.1構造方法
•public SimpleDateFormat()
•public SimpleDateFormat(String pattern)
1.14.2成員方法
•public final String format(Date date)
•public Date parse(String source)
1.15Calendar類
•Calendar類是一個抽象類,它爲特定瞬間與一組諸如YEAR、MONTH、DAY_OF_MONTH、HOUR 等日曆字段之間的轉換提供了一些方法,併爲操作日曆字段(例如獲得下星期的日期)提供了一些方法。
1.15.1成員方法
•public static Calendar getInstance()
•public int get(int field)
•public void add(int field,int amount)
•public final void set(int year,int month,int date)