String

1.String类的概述
什么是字符串
字符串是由多个字符组成的一串数据(字符序列)
字符串可以看成是字符数组
2.String类的构造方法

public String():空构造
public String(byte[] bytes):把字节数组转成字符串	
public String(byte[] bytes,int index,int length):把字节数组的一部分转成字符串
public String(char[] value):把字符数组转成字符串
public String(char[] value,int index,int count):把字符数组的一部分转成字符串
public String(String original):把字符串常量值转成字符串
public int length():返回此字符串的长度。

3.String的特点
一旦被创建就不能改变
4.String类的判断功能

public boolean equals(Object obj):
比较字符串的内容是否相同,区分大小写
public boolean equalsIgnoreCase(String str):		
比较字符串的内容是否相同,忽略大小写
public boolean contains(String str):				
判断字符串中是否包含传递进来的字符串
public boolean startsWith(String str):				
判断字符串是否以传递进来的字符串开头
public boolean endsWith(String str):				
判断字符串是否以传递进来的字符串结尾
public boolean isEmpty():						
判断字符串的内容是否为空串""。

5.String类的获取功能

public int length():							
获取字符串的长度。
public char charAt(int index):					
获取指定索引位置的字符
public int indexOf(int ch):						
返回指定字符在此字符串中第一次出现处的索引。
public int indexOf(String str):					
返回指定字符串在此字符串中第一次出现处的索引。
public int indexOf(int ch,int fromIndex):			
返回指定字符在此字符串中从指定位置后第一次出现处的索引。
public int indexOf(String str,int fromIndex):		
返回指定字符串在此字符串中从指定位置后第一次出现处的索引。
public String substring(int start):				
从指定位置开始截取字符串,默认到末尾。
public String substring(int start,int end):		
从指定位置开始到指定位置结束截取字符串。

StringBuffer
StringBuffer类的概述:线程安全的可变字符序列
1.StringBuffer的构造方法:
public StringBuffer(): 无参构造方法
public StringBuffer(int capacity): 指定容量的字符串缓冲区对象
public StringBuffer(String str): 指定字符串内容的字符串缓冲区对象
2.StringBuffer的方法:
public int capacity():返回当前容量 理论值
public int length(): 返回长度 实际值
3.StringBuffer的添加功能:
public StringBuffer append(String str):
可以把任意类型数据添加到字符串缓冲区里面,并返回字符串缓冲区本身
public StringBuffer insert(int offset,String str):
在指定位置把任意类型的数据插入到字符串缓冲区里面,并返回字符串缓冲区本身
4.StringBuffer的删除功能:
public StringBuffer deleteCharAt(int index):
删除指定位置的字符,并返回本身
public StringBuffer delete(int start,int end):
删除从指定位置开始指定位置结束的内容,并返回本身
5.StringBuffer的替换功能
public StringBuffer replace(int start,int end,String str):
从start开始到end用str替换
6.StringBuffer的反转功能
public StringBuffer reverse():
字符串反转
7.StringBuffer的截取功能
public String substring(int start):
从指定位置截取到末尾
public String substring(int start,int end):
截取从指定位置开始到结束位置,包括开始位置,不包括结束位置

API的学习
1.下载API
2.连接API和ECLIPSE
3.产看API以Sting为例
4.查找方式:
①只知道类名
5.String具体解释:
汉化帮助很大
在线API解释器可以协同工作

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值