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:字 ...
随机推荐
- Hive 报错:java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
在配置好hive后启动报错信息如下: [walloce@bigdata-study- hive--cdh5.3.6]$ bin/hive Logging initialized using confi ...
- springboot elasticsearch 集成注意事项
文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es ...
- 展示博客(Beta版本)
团队:xjbz 1. 团队成员博客,源码仓库地址. coding:https://git.coding.net/z404395979/xjbz.git 钟平辉(071):http://www.cnbl ...
- 《Language Implementation Patterns》之 符号表
前面的章节我们学会了如何解析语言.构建AST,如何访问重写AST,有了这些基础,我们可以开始进行"语义分析"了. 在分析语义的一个基本方面是要追踪"符号",符号 ...
- Linux下ip配置与网络重启
ip配置 //以下ip配置重启失效 sudo ifconfig 192.168.1.1 sudo ifconfig 192.168.1.1 netmask 255.255.255.0 网络重启 //关 ...
- 为label或者textView添加placeHolder
Tip:使用textView的代理需要在头文件中加入: <UITextViewDelegate> h文件 @interface FeedbackViewController : UIVie ...
- SENet
 \(\bf F_{tr}\) 为标准卷积操作 \(\bf F_{sq}\) 为 Global Average Pooling \(\bf F_{ex}\) 为两层全连接网络(可以看做两个1×1卷积 ...
- JavaScript Cookie使用实例
# Session-Cookie // 利用Cookie防止在1分钟内多次提交: function SetCookie (name, value) { var Days = 30; var exp ...
- C#之Socket通信
0.虽然之前在项目中也有用过Socket,但始终不是自己搭建的,所以对Server,Clinet端以及心跳,断线重连总没有很深入的理解,现在自己搭建了一遍加深一下理解. 服务端使用WPF界面,客户端使 ...
- Python-函数-Day4
1.函数 1.1.集合 主要作用: 去重 关系测试, 交集\差集\并集\反向(对称)差集 a = {1,2,3,4} b ={3,4,5,6} a {1, 2, 3, 4} type(a) <c ...