Java常用类库,总结一览

常用类库:

PS:同名重载只记录一个

1、java.lang.Objects:

  1. static boolean equals​(Object a, Object b) 返回 true如果参数相等,否则 false。
  2. static <T> int compare​(T a, T b, Comparator<? super T> c) 如果参数相同则返回0,否则返回 c.compare(a, b) 。 
  3. static int hash​(Object... values) 为一系列输入值生成哈希码。 
  4. static int hashCode​(Object o) 返回非的哈希码 null参数,0为 null的论点。 
  5. static boolean isNull​(Object obj) 返回 true如果提供的参考是 null ,否则返回 false 。 
  6. static boolean nonNull​(Object obj) 返回 true如果提供的参考是非 null否则返回 false 。 
  7. static <T> T requireNonNull​(T obj) 检查指定的对象引用是否不是 null 。 
  8. static <T> T requireNonNull​(T obj, String message) 检查指定的对象引用是否为null ,如果是,则抛出自定义的NullPointerException 。

2、java.lang.Math:

a.字段:

  1. static double E double值比任何其他值更接近 e ,即自然对数的基数。 
  2. static double PI double值比任何其他 pi更接近,圆的圆周与其直径的比率。 

b.方法:

  1. static double abs​(double a) 返回 double值的绝对值。
  2. static double asin​(double a) 返回值的反正弦值; 返回的角度在-pi / 2到pi / 2的范围内。 
  3. static double atan​(double a) 返回值的反正切值; 返回的角度在-pi / 2到pi / 2的范围内。 
  4. static double sqrt​(double a) 返回 double值的正确舍入正平方根。 
  5. static float nextDown​(float f) 返回负无穷大方向上与 f相邻的浮点值。 
  6. static double nextUp​(double d) 返回正无穷大方向上与 d相邻的浮点值。 
  7. static double nextAfter​(double start, double direction) 返回第二个参数方向上第一个参数旁边的浮点数。 
  8. static double exp​(double a) 返回e的a次方 , double值。 
  9. static double pow​(double a, double b) 返回a的b次方。
  10. static double random() 返回带有正号的 double值,大于或等于 0.0且小于 1.0 。 

11)static double floor​(double a) 返回小于或等于参数且等于数学整数的最大值,参考系:正无穷大。

12)static long round​(double a) 返回与参数最接近的 long ,并将关系四舍五入,参考系:正无穷大。 

13)static long max​(long a, long b) 返回两个 long值中较大的 long 。 

14)static double min​(double a, double b) 返回两个 double值中较小的 double 。 

3、java.util.Arrays:

  1. 方法:
  1. static <T> List<T> asList​(T... a) 返回由指定数组支持的固定大小的列表。
  2. static int binarySearch​(byte[] a, byte key) 使用二进制搜索算法在指定的字节数组中搜索指定的值。 
  3. static int binarySearch​(byte[] a, int fromIndex, int toIndex, byte key) 使用二进制搜索算法搜索指定值的指定字节数组的范围。 
  4. static int compare​(boolean[] a, boolean[] b) boolean字典顺序比较两个 boolean阵列。 
  5. static int compare​(boolean[] a, int aFromIndex, int aToIndex, boolean[] b, int bFromIndex, int bToIndex) 在指定范围内按字典顺序比较两个 boolean阵列。
  6. static <T> T[] copyOf​(T[] original, int newLength) 使用空值复制指定的数组,截断或填充(如有必要),以使副本具有指定的长度。 
  7. static <T,​U> T[] copyOf​(U[] original, int newLength, Class<? extends T[]> newType) 使用空值复制指定的数组,截断或填充(如有必要),以使副本具有指定的长度。 

Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain null. Such indices will exist if and only if the specified length is greater than that of the original array. The resulting array is of the class newType.

Type Parameters:

U - the class of the objects in the original array

T - the class of the objects in the returned array

Parameters:

original - the array to be copied

newLength - the length of the copy to be returned

newType - the class of the copy to be returned

Returns:

a copy of the original array, truncated or padded with nulls to obtain the specified length

8、static <T> T[] copyOfRange​(T[] original, int from, int to) 将指定数组的指定范围复制到新数组中。 

9、static <T,​U> T[] copyOfRange​(U[] original, int from, int to, Class<? extends T[]> newType) 将指定数组的指定范围复制到新数组中。 

10、public static String deepToString(Object[] a)

11、public static boolean deepEquals(Object[] a1, Object[] a2)

Returns true if the two specified arrays are deeply equal to one another. Unlike the equals(Object[],Object[]) method, this method is appropriate for use with nested arrays of arbitrary depth.

Two array references are considered deeply equal if both are null, or if they refer to arrays that contain the same number of elements and all corresponding pairs of elements in the two arrays are deeply equal.

Two possibly null elements e1 and e2 are deeply equal if any of the following conditions hold:

e1 and e2 are both arrays of object reference types, and Arrays.deepEquals(e1, e2) would return true

e1 and e2 are arrays of the same primitive type, and the appropriate overloading of Arrays.equals(e1, e2) would return true.

e1 == e2

e1.equals(e2) would return true.

Note that this definition permits null elements at any depth.

If either of the specified arrays contain themselves as elements either directly or indirectly through one or more levels of arrays, the behavior of this method is undefined.

Parameters:

a1 - one array to be tested for equality

a2 - the other array to be tested for equality

Returns:

true if the two arrays are equal

12、static <T> void sort​(T[] a, Comparator<? super T> c) 根据指定比较器引发的顺序对指定的对象数组进行排序。 

13、static String toString​(Object[] a) 返回指定数组内容的字符串表示形式。 

4、java.math.BigDecimal:

  1. 方法:
  1. BigDecimal add​(BigDecimal augend) 返回 BigDecimal其值为 (this + augend) ,其比例为 max(this.scale(), augend.scale()) 。 
  2. BigDecimal subtract​(BigDecimal subtrahend) 返回 BigDecimal其值为 (this - subtrahend) ,其比例为 max(this.scale(), subtrahend.scale()) 。 
  3. BigDecimal multiply​(BigDecimal multiplicand) 返回 BigDecimal其值为 (this × multiplicand) ,其比例为 (this.scale() + multiplicand.scale()) 。 
  4. BigDecimal divide​(BigDecimal divisor) 返回BigDecimal其值为(this / divisor) ,其首选比例为(this.scale() - divisor.scale()) ; 如果无法表示准确的商(因为它具有非终止的十进制扩展),则抛出ArithmeticException 。 
  5. BigDecimal pow​(int n) 返回 BigDecimal其值为 (thisn) ,精确计算功率,精度无限制。 
  6. int intValue() 将 BigDecimal成 int 。 
  7. int intValueExact() 将 BigDecimal转换为 int ,检查是否丢失了信息。 
  8. BigDecimal max​(BigDecimal val) 返回 BigDecimal和 val 。 
  9. BigDecimal min​(BigDecimal val) 返回 BigDecimal和 val 。 
  10. BigDecimal movePointLeft​(int n) 返回一个 BigDecimal ,相当于这个小数点向左移动 n位置。 
  11. BigDecimal movePointRight​(int n) 返回一个 BigDecimal ,相当于这个小数点向右移动 n位置。 
  12. String toPlainString() 返回此 BigDecimal的字符串表示形式,不带指数字段。 
  13. String toString() 如果需要指数,则使用科学计数法返回此 BigDecimal的字符串表示形式。 
  14. static BigDecimal valueOf​(double val) 转换一个 double成 BigDecimal ,使用 double通过所提供的规范的字符串表示 Double.toString(double)方法。 
  15. static BigDecimal valueOf​(long val) 将 long值转换为 BigDecimal ,其标度为零。 
  16. static BigDecimal valueOf​(long unscaledVal, int scale)返回值为:unscaledVal × (10的(-scale)次方)
  1. java.util.Date:

  1. 构造方法

1)Date() 分配 Date对象并对其进行初始化,使其表示分配时间,测量 Date到毫秒。 

2)Date​(long date) 分配 Date对象并初始化它以表示自标准基准时间(称为“纪元”)以来的指定毫秒数,即1970年1月1日00:00:00 GMT。 

  1. 方法

1)long getTime() 返回自此 Date对象表示的1970年1月1日00:00:00 GMT以来的毫秒数。 

2)void setTime​(long time) 将此 Date对象设置为表示格林尼治标准时间1970年1月1日00:00:00之后的 time毫秒的时间点。 

 

5、java.text.SimpleDateFormat

  1. 构造方法

1)SimpleDateFormat​(String pattern) 构造一个 SimpleDateFormat使用给定的模式和默认的默认日期格式符号 FORMAT区域设置。 

2)SimpleDateFormat​(String pattern, DateFormatSymbols formatSymbols) 使用给定的模式和日期格式符号构造 SimpleDateFormat 。 

  1. 方法

1)void applyLocalizedPattern​(String pattern) 将给定的本地化模式字符串应用于此日期格式。 

2)String format​(Date date) 将Date格式化为日期时间字符串。 

3)Date parse​(String source) 从给定字符串的开头解析文本以生成日期。 

4)void applyPattern​(String pattern) 将给定的模式字符串应用于此日期格式。

5)String toLocalizedPattern() 返回描述此日期格式的本地化模式字符串。 

6)String toPattern() 返回描述此日期格式的模式字符串。

7)void setDateFormatSymbols​(DateFormatSymbols newFormatSymbols) 设置此日期格式的日期和时间格式符号。 

8)public Date parse​(String text, ParsePosition pos) 解析字符串中的文本以生成Date 。

该方法尝试从pos给出的索引处开始解析文本。 如果解析成功,则在使用最后一个字符之后将索引pos更新为索引(解析不一定使用直到字符串末尾的所有字符),并返回解析的日期。 更新的pos可用于指示下一次调用此方法的起点。 如果发生错误,则不更改索引pos ,将错误索引pos设置为发生错误的字符的索引,并返回null。

7)String toPattern() 返回描述此日期格式的模式字符串。 

  1. 格式:

y   :   年          H   :   时

M   :   月          m   :   分

d   :   日          s   :   秒

“yyyy年MM月dd日 HH:mm ss” // 就是用这些字符代替占位数据,其他文本自己指定

6、java.util.Calendar

  1. 字段:
  1. static int DATE get和 set字段编号表示当月的日期。 
  2. static int DAY_OF_MONTH get和 set字段编号表示当月的日期。 
  3. static int DAY_OF_WEEK 字段编号为 get和 set表示星期几。 
  4. static int DAY_OF_WEEK_IN_MONTH get和 set字段编号,表示当前月份中某一天的序号。 
  5. static int DAY_OF_YEAR get和 set字段编号表示当年的日期编号。 
  6. static int MONTH get和 set字段编号表示月份。 
  7. protected long time 此日历的当前设置时间,以1970年1月1日格林威治标准时间0:00:00之后的毫秒数表示。
  8. static int WEEK_OF_MONTH get和 set字段编号, get set的周数。 
  9. static int WEEK_OF_YEAR get和 set字段编号表示当前年份的周数。 
  10. static int YEAR 字段编号为 get和 set表示年份。 
  1. 构造方法:

1)static Calendar getInstance() 使用默认时区和区域设置获取日历。 

2)static Calendar getInstance​(Locale aLocale) 使用默认时区和指定的区域设置获取日历。 

  1. 方法:

1)int get​(int field) 返回给定日历字段的值。// field就用Calendar.来访问内部成员变量

2)void set​(int field, int value) 将给定的日历字段设置为给定值。 

3)abstract void add​(int field, int amount) 根据日历的规则,将指定的时间量添加或减去给定的日历字段。 

4)int getActualMaximum​(int field) 给定此 Calendar的时间值,返回指定日历字段可能具有的最大值,同样也有获取最小的方法。 

5)Date getTime() 返回一个 Date对象,表示此 Calendar的时间值(距离 Epoch的毫秒偏移量)。 

6)void setFirstDayOfWeek​(int value) 设定一周的第一天是什么; 例如, SUNDAY在美国, MONDAY在法国。 

7)void setMinimalDaysInFirstWeek​(int value) 设定一年中第一周所需的最小天数; 例如,如果第一周定义为包含一年中第一个月的第一天的那一周,则使用值1调用此方法。

8)void setTime​(Date date) 使用给定的 Date设置此日历的时间。 

9)Instant toInstant() 将此对象转换为Instant 。 

10)String toString() 返回此日历的字符串表示形式。 

7、java.lang.String

a.  字段:

1)String​(byte[] bytes, String charsetName) 构造一个新的String由指定用指定的字节的数组解码charset 。 

2)String​(char[] value) 分配新的 String ,使其表示当前包含在字符数组参数中的字符序列。 

3)String​(byte[] bytes) 通过使用平台的默认字符集解码指定的字节数组构造新的 String 。

b.方法:

  1. char charAt​(int index) 返回指定索引处的 char值。 
  2. IntStream chars() 返回 int的流,将此序列中的 char值零扩展。
  3. int codePointAt​(int index) 返回指定索引处的字符(Unicode代码点)。 
  4. int codePointBefore​(int index) 返回指定索引之前的字符(Unicode代码点)。 
  5. int compareTo​(String anotherString) 按字典顺序比较两个字符串。 
  6. int compareToIgnoreCase​(String str) 按字典顺序比较两个字符串,忽略大小写差异。 
  7. boolean contains​(CharSequence s) 当且仅当此字符串包含指定的char值序列时,才返回true。 
  8. boolean contentEquals​(CharSequence cs) 将此字符串与指定的CharSequence 对比。 当且仅当此String表示与指定序列相同的char值序列时,结果为true 。 请注意,如果CharSequence是StringBuffer则该方法会对其进行同步。
  9. boolean endsWith​(String suffix) 测试此字符串是否以指定的后缀结尾。
  10.  boolean equalsIgnoreCase​(String anotherString) 将此 String与另一个 String比较,忽略了大小写。 
  11. byte[] getBytes() 使用平台的默认字符集将此 String编码为字节序列,将结果存储到新的字节数组中。 
  12. byte[] getBytes​(String charsetName) 使用命名的字符集将此 String编码为字节序列,将结果存储到新的字节数组中。 
  13. void getChars​(int srcBegin, int srcEnd, char[] dst, int dstBegin)
  14. int indexOf​(int ch) 返回指定字符第一次出现的字符串中的索引。 
  15. int indexOf​(int ch, int fromIndex) 返回指定字符第一次出现的此字符串中的索引,从指定索引处开始搜索。
  16. int indexOf​(String str) 返回指定子字符串第一次出现的字符串中的索引。 
  17. int indexOf​(String str, int fromIndex) 从指定的索引处开始,返回指定子字符串第一次出现的字符串中的索引。 
  18. boolean isBlank() 如果字符串为空或仅包含 white space代码点,则返回 true ,否则 false 。 
  19. boolean isEmpty() 返回 true ,当且仅当, length()是 0 。 
  20. int lastIndexOf​(int ch) 返回指定字符最后一次出现的字符串中的索引。 
  21. int lastIndexOf​(int ch, int fromIndex) 返回指定字符最后一次出现的字符串中的索引,从指定的索引开始向后搜索。 
  22. int lastIndexOf​(String str) 返回指定子字符串最后一次出现的字符串中的索引。 
  23. int lastIndexOf​(String str, int fromIndex) 返回指定子字符串最后一次出现的字符串中的索引,从指定索引开始向后搜索。 
  24. int length() 返回此字符串的长度。 
  25. Stream<String> lines() 返回从此字符串中提取的行的流,由行终止符分隔。 
  26. boolean matches​(String regex) 判断此字符串是否与给定的 regular expression匹配
  27. boolean regionMatches​(boolean ignoreCase, int toffset, String other, int ooffset, int len) 测试两个字符串区域是否相等:将此String对象的子字符串与参数other的子字符串进行比较 。 如果这些子串表示相同的字符序列,则结果为true ,当且仅当ignoreCase为真时,忽略大小写。 要比较的此String对象的子字符串从索引toffset开始,长度为len 。 要比较的子字符串other从索引ooffset开始,长度为len
  28. String replace​(char oldChar, char newChar) 返回一个用newChar替换oldChar的新String
  29. String replace​(CharSequence target, CharSequence replacement) 将此字符串中与文字目标序列匹配的每个子字符串替换为指定的文字替换序列。 
  30. String replaceAll​(String regex, String replacement)将原字符串中,每个和给定 regular expression匹配的子字符串替换为replacement。 
  31. String replaceFirst​(String regex, String replacement) 将原字符串中,第一个和给定 regular expression匹配的子字符串替换为replacement
  32. public String[] split​(String regex, int limit)

此方法返回的数组包含此字符串的每个子字符串,该子字符串由与给定表达式匹配的另一个子字符串终止,或者由字符串的结尾终止。 数组中的子串按它们在此字符串中出现的顺序排列。 如果表达式与输入的任何部分都不匹配,那么结果数组只有一个元素,即该字符串。

当在该字符串的开头存在正宽度匹配时,在结果数组的开头包含空的前导子字符串。 然而,开头的零宽度匹配从不会产生这样的空前导子串。

limit参数控制应用模式的次数,因此会影响结果数组的长度。

如果限制为正,则模式将应用最多限制 - 1次,数组的长度不会超过限制 ,并且数组的最后一个条目将包含超出最后一个匹配分隔符的所有输入。

如果限制为零,则模式将尽可能多地应用,数组可以具有任何长度,并且将丢弃尾随空字符串。

如果限制为负,则模式将尽可能多地应用,并且数组可以具有任何长度。

例如,字符串"boo:and:foo"使用以下参数生成以下结果:

Regex

Limit

Result

:

2

{ "boo", "and:foo" }

5

{ "boo", "and", "foo" }

-2

{ "boo", "and", "foo" }

o

5

{ "b", "", ":and:f", "", "" }

-2

{ "b", "", ":and:f", "", "" }

0

{ "b", "", ":and:f" }

调用str形式的这个方法。 split( regex , n )产生与表达式相同的结果

Pattern.compile(regex).split(str, n)   // 这是啥?

  1. boolean startsWith​(String prefix) 测试此字符串是否以指定的前缀开头。 
  2. boolean startsWith​(String prefix, int toffset) 测试从指定索引开始的此字符串的子字符串是否以指定的前缀开头。 
  3. String strip() 返回一个字符串,其值为此字符串,并删除了所有前导和尾随 white space 。 
  4. String stripLeading() 返回一个字符串,其值为此字符串,并删除了所有前导 white space 。 
  5. String stripTrailing() 返回一个字符串,其值为此字符串,并删除所有尾随 white space 。 
  6. CharSequence subSequence​(int beginIndex, int endIndex) 返回作为此序列的子序列的字符序列。 [beginIndex, endIndex)
  7. char[] toCharArray() 将此字符串转换为新的字符数组。 
  8. String toLowerCase() 使用默认语言环境的规则将此 String所有字符转换为小写。
  9. String toLowerCase​(Locale locale) 使用给定 Locale的规则将此 String所有字符转换为 Locale 。
  10. String toUpperCase() 使用默认语言环境的规则将此 String所有字符转换为大写。 
  11. String toUpperCase​(Locale locale) 使用给定 Locale的规则将此 String所有字符转换为大写。 
  12. String trim() 返回一个字符串,其值为此字符串,删除了所有前导和尾随空格,其中space被定义为其代码点小于或等于 'U+0020' (空格字符)的任何字符。 
  13. static String valueOf​(boolean b) 返回 boolean参数的字符串表示形式。
  14. static String valueOf​(char[] data, int offset, int count) 返回 char数组参数的特定子数组的字符串表示形式。 

8、java.util.Map

1、Set<Map.Entry<K,​V>> entrySet() 返回的是存着Map.Entry的Set,遍历起来比keySet方便。

9、java.util.Collection

1、default Stream<E> stream()   返回一个Stream(这个Stream不是什么字节流,而是一种容器)

10、java.util.Stream

1、 map 方法是将现在的 stream 里的东西,都通过一个 function 的流程,变成新的东西。而非降维或是转成map。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值