java_5.21_1

来源:互联网 发布:软件开发项目售后服务 编辑:程序博客网 时间:2024/05/19 01:08

//从较大字符串中提取子串

String g1="Hello";

String s=g1.substring(0,3);

System.out.println(s);//输出Hel (0,1,2)位

//g1.substring(a,b); 输出长度为b-a


//检测两个字符串是否相等

s.equals(t);

"Hello".equals(g1);//合法

//检测两个字符串是否相等,不区分大小写

s.equalsIgnoreCase(t);


if(g1.compareTo("Hello")==0)//比较


//返回代所需要的代码单元数

int n=g1.length();//is 5

int count=g1.codePointCount(0,greeting.length());//实际长度,代码点

//http://bbs.csdn.net/topics/340195349

//s.charAt(n) 将返回位置n的代码单元,n介于0~s.length()-1之间

char first=g1.charAt(0);//first is "H"

//要想得到第i个代码点

int index=g1.offsetByCodePoints(0,i);

int cp=g1.codePointAt(index);

原创粉丝点击