java String的各种方法及操作
|
No. |
方法名称 |
功能 |
|
字符与字符串 |
||
|
01 |
public String(char[] value) |
将字符数组中所有内容变为字符串 |
|
02 |
public String(char[] value,int offset,int count) |
将字符数组中部分内容变为字符串 |
|
03 |
public char charAt(int index) |
取得指定索引位置的字符,索引从0开始 |
|
04 |
public char[] toCharArray() |
将字符串变为字符数组返回 |
|
字节与字符串 |
||
|
01 |
public String(byte[] bytes) |
将字节数组中所有内容变为字符串 |
|
02 |
public String(byte[] bytes,int offset,int length) |
将字节数组中部分内容变为字符串 |
|
03 |
public byte[] getBytes() |
将字符串以字节数组的形式返回 |
|
04 |
public byte[] getBytes(String charsetName) throws UnsupportedEncodingExcepetion |
编码转换处理 |
|
字符串比较 |
||
|
01 |
public boolean equals(String anObject) |
区分大小写比较 |
|
02 |
public boolean equalsIgnoreCase(String anotherString) |
不区分大小写比较 |
|
03 |
public int compareTo(String anotherString) |
比较两个字符串的大小关系 |
|
字符串查找 |
||
|
01 |
public boolean contains(String s) |
判断一个子字符串是否存在(JDK1.5以后才有) |
|
02 |
public int indexOf(String str) |
从头开始查找指定字符的位置,查到了返回位置的开始索引,查不到返回-1(JDK1.5以后推荐使用contains) |
|
03 |
public int indexOf(String str,int fromIndex) |
从指定位置查找子字符的位置 |
|
04 |
public int lastIndex(String str) |
从后往前查找子字符的位置 |
|
05 |
public int lastIndex(String str,int fromIndex) |
从指定位置由后往前查找子字符的位置 |
|
06 |
public boolean startsWith(String prefix) |
从头开始判断是否以指定的字符串开头 |
|
07 |
public boolean startsWith(String prefix,int toffset) |
从指定位置开始判断是否以指定的字符串开头 |
|
08 |
public boolean endsWith(String suffix) |
判断是否以指定的字符串结尾 |
|
字符串替换 |
||
|
01 |
public String replaceAll(String regex,String replacement) |
替换所有内容 |
|
02 |
public String replaceFirst(String regex,String replacement) |
替换首个内容 |
|
字符串拆分 |
||
|
01 |
public String[] split(String regex) |
将字符串全部拆分 |
|
02 |
public String[] split(String regex,int limit) |
将字符串部分拆分,该数组长度就是limit |
|
字符串截取 |
||
|
01 |
public String substring(int beginIndex) |
从指定索引截取到结尾 |
|
02 |
public String substring(int beginIndex,int endIndex) |
截取部分内容 |
|
其他操作 |
||
|
01 |
public String trim() |
去掉字符串中的左右空格,保留中间空格 |
|
02 |
public String toUpperCase() |
字符串转大写 |
|
03 |
public String toLowerCase() |
字符串转小写 |
|
04 |
public String interm() |
字符串入对象池 |
|
05 |
public String concat(String str) |
字符串连接,等同于”+” |
|
06 |
public int length() |
取得字符串长度 |
|
07 |
public boolean inEmpty() |
判断是否为空(不是null,而是长度为空) |
java String的各种方法及操作的更多相关文章
- java String拼接的方法选择及性能分析
String 拼接的方法选择 在拼接静态字符串时,尽量用 +,因为通常编译器会对此做优化,如: String test = "this " + "is " + ...
- java String 中 intern方法的概念
1. 首先String不属于8种基本数据类型,String是一个对象. 因为对象的默认值是null,所以String的默认值也是null:但它又是一种特殊的对象,有其它对象没有的一些特性. 2. ne ...
- java String的intern()方法
intern()方法用于将字符串对象加入常量池中. public native String intern(); intern()方法返回的是一个常量池中的String对象(即常量池中某个String ...
- java String 提供的方法
String类的判断功能: * boolean equals(Object obj):比较字符串的内容是否相同,区分大小写 * boolean equalsIgnoreCase(String str) ...
- java String类 trim() 方法源码分析
public String trim() { int arg0 = this.value.length; //得到此字符串的长度 int arg1 = 0; //声 ...
- java.String中的方法
(String) str.trim() 该方法返回一个复制该字符串的开头和结尾的白色空格去掉,或字符串,如果它没有头或尾空白. (Boolean) str.contains(str1) 判断 str ...
- JAVA String类型的一些小操作
String类型是否包含某个String类型的函数:源字符串.contains(包含字符串) 返回值为:boolean类型(true或false) String类型把某个字符替换成另一个字符:源字符 ...
- 【blog】批量删除时,guava Splitter与Java String的split 方法有什么区别
参考链接 http://www.cnblogs.com/hxfirefox/p/4832913.html
- Java—String,StringBuffer,StringBuilde区别和操作
Java语言有关字符串的类有三种 java.lang.String:一般作为简单字符串类型 java.lang.StringBuffer:字符串缓冲区 java.lang.StringBuider:字 ...
随机推荐
- iOS App 启动性能优化
1. App启动过程 解析Info.plist 加载相关信息,例如如闪屏 沙箱建立.权限检查 Mach-O加载 如果是胖二进制文件,寻找合适当前CPU类别的部分 加载所有依赖的Mach-O文件(递归调 ...
- 【HTTP协议】---HTTP协议详解
HTTP协议详解 一.HTTP简介 1.HTTP协议,即超文本传输协议(Hypertext transfer protocol).是一种详细规定了浏览器和万维网(WWW = World Wide We ...
- Linux下的指令:find,which
1. 在Linux系统下,使用find来查找文件: find [path] [condition] [operation] path指定了在哪个目录查找,condition限定了查找条件,operat ...
- C语言实现Linux命令——od
C语言实现Linux命令--od 实现要求: 复习c文件处理内容 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能 main与其他分开,制作静态库和动态库 编写M ...
- Linux kernel 的 sendfile 是如何提高性能的
Linux kernel 的 sendfile 是如何提高性能的 现在流行的 web 服务器里面都提供 sendfile 选项用来提高服务器性能,那到底 sendfile 是什么,怎么影响性能的呢? ...
- 多线程socket UDP收发数据
多线程socket收发数据 from threading import Thread from socket import * def sendData(): while True: sendInfo ...
- 在arc模式下 CGImage 释放问题
//大图bigImage //定义myImageRect,截图的区域 if (imagecount >= 3) { CGRect myImageRect; if (i.size.width< ...
- linux的slect的脚本适用于交互
[rhuang@localhost ~]$ vi os.sh #!/bin/bash echo "What is your favourite OS?" select var in ...
- 使用IDEA快速插入数据库数据的方法
如上图所示:数据库创建表主键使用了自增列自增因此忽略,只有后两列非主键得数据,在数据较多得时候使用IDEA快捷键Ctrl+R键,快速查找替换.
- Python内置函数(53)——setattr
英文文档: setattr(object, name, value) This is the counterpart of getattr(). The arguments are an object ...