一、Arrays类
java.util.Arrays类 用于操作数组工具类,里面定义了常见操作数组的静态方法。
1.equals 方法
比较两个非同一数组是否相等,而数组本身的equals判断另一个数 组是否它本身。 声明:public static boolean equals(type[]a,type[]a2) 参数的类型可以是原生数据类型和引用类型的任意一种类型。返回:如果两个相等,则返回true,否则返回false
2.sort方法
对数组中的元素进行排序
自定义对象排序 自定义类实现Comparable接口 重写compareTo方法
3.binarySearch -使用二分搜索算法搜索指定数组
声明
public static int binarySearch(type[] a, type key)
public static int binarySearch(long[] a,int fromIndex,int toIndex,long key)
描述: 使用二分搜索算法搜索指定的type型数组,以获得指定的值。
参数: a - 要搜索的数组。 key - 要搜索的值。 fromIndex - 要排序的第一个元素的索引(包括)。 toIndex - 要排序的最后一个元素的索引(不包括)。 type -byte、double、float、object、long、int、short、char
4.To String 方法
声明:public static String toString(type[] a)
描述:返回指定数组内容的字符串表示形式。
基本数组,字符串表示形式由数组的元素列表组成,括在[],相邻元素 用“ , ”(逗号加空格)分隔
五、String类
创建字符串对象有两种创建方法
第一种: String s = "abc"; 先在栈中创建一个对String类的对象引用变量s,然后去字符串常量池中查找 有没有"abc", 如果没有则在常量池中添加”abc”, s引用变量指向常量池中 的”abc”,如果常量池中有,则直接指向改地址即可,不用重新创建.
第二种: 一概在堆中创建新对象,值存储在堆内存的对象中。 String s = new String("abc")
构造方法
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)