黑马程序员--常用API

1:String类(掌握)
(1)字符串:多个字符组成的一串数据。
(2)构造方法:
A:String s = new String();
B:String s = new String(byte[] bys);
C:String s = new String(byte[] bys,int index,int length);
D:String s = new String(char[] chs);
E:String s = new String(char[] chs,int index,int length);
F:String s = new String(String str);
G:String s = "hello";
(3)字符串的特点及面试题
A:字符串一旦被赋值,就不能改变。
注意:字符串的值不能改变,没有说引用变量不能改变。
B:面试题:
a:String s = new String("hello")和String s = "hello"的区别。
b:请写出结果:
String s1 = new String("hello");
String s2 = new String("hello");
System.out.println(s1==s2);
System.out.println(s1.equals(s2));


String s3 = new String("hello");
String s4 = "hello";
System.out.println(s3==s4);
System.out.println(s3.equals(s4));


String s5 = "hello";
String s6 = "hello";
System.out.println(s5==s6);
System.out.println(s5.equals(s6));
(4)成员方法
A:判断功能
boolean equals(Object obj)
boolean equalsIgnoreCase(String str)
boolean contains(String str)
boolean startsWith(String str)
boolean endsWith(String str)
boolean isEmpty()
B:获取功能
int length()
char charAt(int index)
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)
C:转换功能
byte[] getBytes()
char[] toCharArray()
static String copyValueOf(char[] chs)
static String valueOf(char[] chs)
static String valueOf(int i)
String toLowerCase()
String toUpperCase()
String concat(String str)


D:其他功能
a:替换功能
String replace(char oldChar,char newChar)
String replace(String oldString,String newString)


b:切割功能
String[] split(String regex)

c:去除两端空格功能
String trim()

d:字典顺序比较功能
int compareTo(String str)

int compareToIgnoreCase(String str) 

1:数组操作(理解)
查找
--普通查找:数组无序
--二分查找(折半查找):数组有序


代码:
public static int getIndex(int[] arr,int value)
{
int maxIndex = arr.length-1;
int minIndex = 0;
int midIndex = (maxIndex+minIndex)/2;


while(arr[midIndex]!=value)
{
if(arr[midIndex]>value)
{
maxIndex = midIndex - 1;
}
else if(arr[midIndex]<value)
{
minIndex = midIndex + 1;
}


if(minIndex > maxIndex)
{
return -1;
}


midIndex = (maxIndex+minIndex)/2;
}


return midIndex;
}


2:Arrays工具类的使用(掌握)
(1)Arrays是针对数组操作的工具类。
(2)成员方法:
public static String toString(数组):把数组变成字符串。
public static void sort(数组):对数组进行排序。
public static int binarySearch(int[] arr,int value):二分查找


3:System的方法(掌握)
(1)系统类,提供了静态的变量和方法供我们使用。
(2)成员方法:
public static void exit(int value):退出jvm,非0表示异常退出。
public static long currentTimeMillis():返回当前系统时间的毫秒值。
和1970 年 1 月 1 日午夜之间的时间差


4:StringBuffer(掌握)
(1)字符个数可以发生改变的字符串类。字符串缓冲区类。
(2)构造方法:
A:StringBuffer()
B:StringBuffer(int capacity)
C:StringBuffer(String str)
(3)成员方法:(自己补齐)
A:添加功能
append
insert


B:删除功能
deleteCharAt
delete

C:替换功能
replace

D:截取功能
substring

E:反转功能
reverse
(4)案例:
字符串反转。


5:基本类型包装类(掌握)
(1)基本类型的数据我们只能使用值,不能做更多的操作。为了方便我们操作,
  java就把每种基本类型进行了包装。提供方法供我们使用。
(2)基本类型和包装类的对应关系
byte
short
int Integer
long 
float
double
char Character
boolean
(3)Integer构造方法
A:Integer i = new Integer(int num);
B:Integer i = new Integer(String s);
注意:s必须是一个由数字字符组成的字符串。
(4)String和int类型的转换
A:String -- int
Integer:
public static int parseInt(String s)
B:int -- String
Integer:
public static String toString(int i)
String:
public static String valueOf(int i)
(5)JDK5以后的新特性
A:自动装箱 基本类型--引用类型
B:自动拆箱 引用类型--基本类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值