1.Object 根类,作为每个类的超类(or父类);
public int hashcode();返回对象的哈希码值,理解为地址,不是真正意义上的地址
public final Class getClass();返回类名
public String getName();返回全类名(包名加类名)
public String toString();(直接输出对象名时就是调用 toString(),输出:全类名@16进制数字),若要 返回对象的值而不是全类名@16进制数字,要重写方法(可自动生成ctrl+shift+s)
public boolean equals(Object obj);默认比较地址值,重写后比较对象值
“==”比较值相等(地址值)
Protect Object clone()
public int hashcode();返回对象的哈希码值,理解为地址,不是真正意义上的地址
public final Class getClass();返回类名
public String getName();返回全类名(包名加类名)
public String toString();(直接输出对象名时就是调用 toString(),输出:全类名@16进制数字),若要 返回对象的值而不是全类名@16进制数字,要重写方法(可自动生成ctrl+shift+s)
public boolean equals(Object obj);默认比较地址值,重写后比较对象值
“==”比较值相等(地址值)
Protect Object clone()
2.Scanner 类,文本扫描器,导包:import java.util.Scanner
Scanner类中的一个判断功能:
Public boolean has NextXXX()如:
Scanner sc =new Scanner(System.in)
if(sc.hasNextInt()){
int num=sc.nextInt();
system.out.println(num);
}else{
system.out.println("你输入的数据类型有误");
}
注意:录入一个int型后在录入一个String型,结果是int型和一个空格,因为空格也是一个字符串,解决方法:键盘重新录入Scanner sc =new Scanner(System.in);
3.String 类,表示字符串,默认null
构造方法:
常用方法:
public int length();
public char charAt(int index)返回指定索引处的 字符
public int indexOf(int ch)返回指定字符在此字符串中第一次出现处的索引
问题:既然传入的字符:这里为什么用int类型
'a'和97 都表示a
public int indexOf(int ch,int fromIndex)返回在此字符串中第一次出现指定字符处的索引,从指定的索引开 始搜索。
public int indexOf(String str)返回指定子字符串在此字符串中第一次出现处的索引
public int indexOf(String str,int fromIndex)回在此字符串中第一次出现指定字符串处的索引,从指定的索 引开始搜索。
截取功能
public String substring(int beginIndex):从指定位置开始截取,默认截取到末尾,返回新的字符串
public String substring(int beginIndex, int endIndex):从指定位置开始到指定位置末尾结束,包前不包含
public int length();
public char charAt(int index)返回指定索引处的 字符
public int indexOf(int ch)返回指定字符在此字符串中第一次出现处的索引
问题:既然传入的字符:这里为什么用int类型
'a'和97 都表示a
public int indexOf(int ch,int fromIndex)返回在此字符串中第一次出现指定字符处的索引,从指定的索引开 始搜索。
public int indexOf(String str)返回指定子字符串在此字符串中第一次出现处的索引
public int indexOf(String str,int fromIndex)回在此字符串中第一次出现指定字符串处的索引,从指定的索 引开始搜索。
截取功能
public String substring(int beginIndex):从指定位置开始截取,默认截取到末尾,返回新的字符串
public String substring(int beginIndex, int endIndex):从指定位置开始到指定位置末尾结束,包前不包含
常用转换功能:
public byte[] getBytes() :将字符串转换为字节数组
public char[] toCharArray() :将字符串转换成字符数组(重点)
public static String valueOf(int i):将int类型的数据转换成字符串(重点)
这个方法可以将任何类型的数据转化成String类型
public String toLowerCase():转成小写
public String toUpperCase():字符串中所有的字符变成大写
public byte[] getBytes() :将字符串转换为字节数组
public char[] toCharArray() :将字符串转换成字符数组(重点)
public static String valueOf(int i):将int类型的数据转换成字符串(重点)
这个方法可以将任何类型的数据转化成String类型
public String toLowerCase():转成小写
public String toUpperCase():字符串中所有的字符变成大写
String类的常用的判断功能
boolean equals(Object obj):将此字符串与指定的对象比较
boolean equalsIgnoreCase(String str)将此 String 与另一个 String 比较,不考虑大小写
boolean contains(String str):判断当前大川中是否包含子字符串 (重点)
boolean startsWith(String str):以当前str字符串开头(重点)
boolean endsWith(String str):以当前str字符串结尾(重点)
boolean isEmpty():判断字符串是否为空
String 的拼接功能
public String concat(String str):字符串的特有功能:拼接功能和+拼接符是一个意思
String 的替换功能
public String replace(char oldChar/(String oldStr),char newChar/(String newStr))
String 的去除俩端空格
public String trim();
比较字符串大小:public int compareTo(String str);
4.StringBuffer类
StringBuffer的构造方法:
StringBuffer() :无参构造的形式,初始容量16
StringBuffer(int capacity) :指定容量构造一个字符串缓冲区
StringBuffer(String str) 构造一个字符串缓冲区,并将其内容初始化为指定的字符串内容
StringBuffer的获取功能:
public int length()返回长度
public int capacity()返回当前容量 (如果超过容量,系统自动分配(存储字符串的时候,英文的))
StringBuffer的添加功能
(实际开发中用的多):public StringBuffer append(String/boolean....) :在字符串缓冲区中追加数据(在末尾追 加),并且返回字符串缓冲区本身
public StringBuffer insert(int offset,String str):将当前str字符串添加到指定位置处,它返 回字符串缓冲区本身
StringBuffer的删除功能:
public StringBuffer deleteCharAt(int index):移除指定位置处的字符..
public StringBuffer delete(int start,int end):移除从指定位置处到end-1处的子字符串...
StringBuffer的反转功能:
public StringBuffer reverse() :将缓冲区中的字符序列反转取代,返回它(字符串冲)本身
StringBuffer的截取功能:
public String substring(int start):从指定位置开始截取,默认截取到末尾,返回值不在是缓冲区 本身,而是一个新的字符串
public String substring(int start,int end) :从指定位置开始到指定位置结束截取,包前不包后 ,返回值不在是缓冲区本身,而是一个新的字符串
StringBuffer的替换功能:
public StringBuffer replace(int start,int end,String str)
从指定位置到指定位置结束,用新的str字符串去替换,返回值是字符串缓冲区 本身
StringBuffer和String的区别?
1. 前者是一个可变的字符序列,后者是不可变的字符序列
2. 如果从内存角度考虑,String定义的时候,会在常量池中开辟空间,比较耗费内存
而StringBuffer,字符串缓冲区(里面存储的全部都是字符串),它会释放掉
1. 前者是一个可变的字符序列,后者是不可变的字符序列
2. 如果从内存角度考虑,String定义的时候,会在常量池中开辟空间,比较耗费内存
而StringBuffer,字符串缓冲区(里面存储的全部都是字符串),它会释放掉
5.Integer
Integer提供了静态功能:进制转换
public static String toBinaryString(int i)
public static String toOctalString(int i)
public static String toHexString(int i)
public static String toBinaryString(int i)
public static String toOctalString(int i)
public static String toHexString(int i)
Integer的构造方法:
public Integer(int value)
public Integer(String s)
如何将int转换为String类型
valueOf(int i) ;
将String转换为int类型
static int parseInt(String s);
public Integer(int value)
public Integer(String s)
如何将int转换为String类型
valueOf(int i) ;
将String转换为int类型
static int parseInt(String s);
6.Character类:
Character 类在对象中包装一个基本类型 char 的值。Character 类型的对象包含类型为 char 的单个字段。
以确定字符的类别(小写字母,数字,等等),
构造方法:
public Character(char value)
Character类的判断功能:
public static boolean isDigit(char ch)确定指定字符是否为数字。
public static boolean isLowerCase(int ch): 确定是否是小写字母字符
public static boolean isUpperCase(int ch):确定是否大写字母字符
两个转换功能:
public static int toLowerCase(int codePoint)
public static int toUpperCase(int codePoint)
Character 类在对象中包装一个基本类型 char 的值。Character 类型的对象包含类型为 char 的单个字段。
以确定字符的类别(小写字母,数字,等等),
构造方法:
public Character(char value)
Character类的判断功能:
public static boolean isDigit(char ch)确定指定字符是否为数字。
public static boolean isLowerCase(int ch): 确定是否是小写字母字符
public static boolean isUpperCase(int ch):确定是否大写字母字符
两个转换功能:
public static int toLowerCase(int codePoint)
public static int toUpperCase(int codePoint)
7.
冒泡排序
选择排序
折半查找
冒泡排序
选择排序
折半查找