黑马程序员——看JDK API 1.6.0中文版研究String的用法
来源:互联网 发布:抑郁和悲伤的区别 知乎 编辑:程序博客网 时间:2024/05/23 15:43
------- android培训、java培训、期待与您交流! ----------
一、获取。
1.获取字符串的长度:length()
int
length()
2.获取某个位置上的字符:charAt(int index)
char
charAt(int index)
char
值。 3.获取字符(串)在出现在字符串的哪个位置:indexOf(char ch)
int
indexOf(int ch)
4.也可以返回字符(串)从某处开始的位置索引 indexOf(char ch,int fromIndex)
int
indexOf(int ch, int fromIndex)
5.字符(串)最后一次出现的索引,或者是说,倒叙查看字符出现的位置: lastIndexOf(char ch)
int
lastIndexOf(int ch)
二、判断
1.判断字符串是否为空:isEmpty()
boolean
isEmpty()
length()
为 0 时返回 true。 2.判断两个字符串是否相等:equals()
boolean
equals(Object anObject)
3.判断是否包含某字符串:contains(String str)
boolean
contains(CharSequence s)
4.判断是否已某字符串开头:startwith(String str);
boolean
startsWith(String prefix)
5.判断此字符串从某处开始的子字符串时候以某字符串开头:startWith(Sting srt,int startIndex);
boolean
startsWith(String prefix, int toffset)
6.判断此字符串是否以某字符串结尾:endWith(Sting str);
boolean
endsWith(String suffix)
7.判断两个字符串是否相等,忽略大小写:equalsIgnoreCase(String str)
boolean
equalsIgnoreCase(String anotherString)
String
与另一个 String
比较,不考虑大小写。 三、转换
1.字符转变成字符串:String(char[] value)
String(char[] value)
String
,使其表示字符数组参数中当前包含的字符序列 2.字节转变成字符串:String(byte[] value)
String(byte[] bytes, int offset, int length)
String
。 3.字符串转变成字符:toCharArray(),返回一个字符数组。
char[]
toCharArray()
4.字符串转变成字节:getBytes
byte[]
getBytes()
String
编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 5.字符串转变成全小写:toLowerCase();
String
toLowerCase()
String
中的所有字符都转换为小写。 6.字符串转变成全大写:toUpperCase();
String
toUpperCase()
String
中的所有字符都转换为大写。 7.字符串去掉两头的空字符:trim();
String
trim()
8.其他类型的数据转换成字符串:valueOf(各种类型);
static String
valueOf(boolean b)
boolean
参数的字符串表示形式。static String
valueOf(char c)
char
参数的字符串表示形式。static String
valueOf(char[] data)
char
数组参数的字符串表示形式。static String
valueOf(char[] data, int offset, int count)
char
数组参数的特定子数组的字符串表示形式。static String
valueOf(double d)
double
参数的字符串表示形式。static String
valueOf(float f)
float
参数的字符串表示形式。static String
valueOf(int i)
int
参数的字符串表示形式。static String
valueOf(long l)
long
参数的字符串表示形式。static String
valueOf(Object obj)
Object
参数的字符串表示形式。 9.获取子字符串:subString(int startIndex,int endIndex)
String
substring(int beginIndex, int endIndex)
四、替换和切割、比较
1.替换:replace(String oldString,String newString);
String
replace(char oldChar, char newChar)
newChar
替换此字符串中出现的所有 oldChar
得到的。 2.切割:split(String str),返回一个字符串数组。
String[]
split(String regex)
3.比较:compareTo(String str)
int
compareTo(String anotherString)
int
compareToIgnoreCase(String str)
- 黑马程序员——看JDK API 1.6.0中文版研究String的用法
- 黑马程序员—Java API(String类)
- 黑马程序员——基础学习(八)API中Object、Scanner以及String的用法概述
- 黑马程序员——Java API总结(String)
- 黑马程序员—API
- 黑马程序员—API
- 黑马程序员——JDK
- 黑马程序员--JAVA<API>--String
- 黑马程序员----API之String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 黑马程序员——String
- 堆 与 栈
- 黑马程序员——线程中等待唤醒机制及jdk5版本lock的深入思考
- 2013年 最新面试题
- BaseServlet
- iOS中Http(面试时讲述步骤)
- 黑马程序员——看JDK API 1.6.0中文版研究String的用法
- HttpSessionAttributeListener的例子
- Qt汉化和中文乱码解决
- OpenRisc-2-C to Verilog
- 黑马程序员——FileWriter和FileReader的基本用法
- Convert.ToInt32()与int.Parse()的区别
- 黑马程序员——java中关于awt组件的基本应用初探
- 过客
- Windows 8 中文网址导航隐私声明