Arrays类
–equals 方法
比较两个数组对象中元素是否相等.
而数组对象中的equals用来判断与另一个数组对象是否相等。
声明:public static boolean equals(type[]a,type[]a2)
参数的类型可以是原生数据类型和引用类型的任意一种类型
返回:如果两个相等,则返回true,否则返回false
–sort -排序
作用于数组的所有元素
public static void sort(type[] a)
作用于数组指定范围内的元素
public static void sort(type[] a, int fromIndex(包括), int toIndex(不包括))
将指定的类型数组所有元素按数字升序进行排序
–binarySearch
使用二分搜索算法搜索指定数组
public static int binarySearch(type[] a, type key)
public static int binarySearch(long[] a,int fromIndex,int
toIndex,long key)
参数:
a - 要搜索的数组。
key - 要搜索的值。
fromIndex - 要排序的第一个元素的索引(包括)。
toIndex - 要排序的最后一个元素的索引(不包括)
–copyOf方法
数组复制,将指定数组中的元素复制到一个指定长度的新数组中,并返回
新数组.
static int[] copyOf(int[] a, int newLength)
–fill方法
将指定的int值分配给指定的int数组的每个元素。
fill(int[] a, int val)
–toString() 方法
public static String toString(type[] a)
返回指定数组内容的字符串表示形式
以Integer为例的基本数据类型
静态方法
public static final int MAX_VALUE 最大的int型数(231-1)
public static final int MIN_VALUE 最小的int型数(-231)
构造方法
Integer(int a);
Integer(String a);------字符串必须是纯数字字符串
比较方法
均为比较大小的方法
static int compareTo(Integer a);
boolean equals(Object);
int max(int a,int b);
int min(int a,int b);
转换方法
static toBinaryString(int i);
static String toHexString(int i);
static String toOctalString(int i);
int intValue();
static int parseInt(String s);
String toString();
static Integer valueOf(int i)
static Integer valueOf(String s)
String类
构造方法
public String()
public String(String str)
public String(byte[] bytes)
public String(char[] value)
//分为有参和无参
判断功能
boolean equals(Object obj)
boolean equalsIgnoreCase(String str)
boolean contains(String str)
boolean isEmpty()
boolean startsWith(String prefix)
boolean endsWith(String suffix)
获取功能
int length()
//获取长度
char charAt(int index)
//获取位置
int indexOf(String str)
int indexOf(String str,int fromIndex)
//获取位置,可定义起始位置
String substring(int start)
String substring(int start,int end)
// 截取
转换功能
byte[] getBytes()
char[] toCharArray()
//转为对应类型的数组
String toLowerCase()
String toUpperCase()
//改变大小写
String concat(String str)
Stirng[] split(分割符);
// 分割数组
替换功能
String replace(char old,char new)
String replace(String old,String new)
// 替换所有的指定内容的字符/字符串为新内容
replaceAll(String regex, String replacement)
replaceFirst(String regex, String replacement)
//替换第一个指定内容出现时对应的字符/字符串为新内容
去除字符串两空格
String trim()