JAVA字符串处理函数列表一览
Java中的字符串也是一连串的字符。但是与许多其他的计算机语言将字符串作为字符数组处理不同,Java将字符串作为String类型对象来处理。将字符串作为内置的对象处理允许Java提供十分丰富的功能特性以方便处理字符串。下面是一些使用频率比较高的函数及其相关说明。
substring()
它有两种形式,第一种是:String substring(int startIndex)
第二种是:String substring(int startIndex,int endIndex)
concat() 连接两个字符串
replace() 替换
它有两种形式,第一种形式用一个字符在调用字符串中所有出现某个字符的地方进行替换,形式如下:
String replace(char original,char replacement)
例如:String s=”Hello”.replace(’l',’w');
第二种形式是用一个字符序列替换另一个字符序列,形式如下:
String replace(CharSequence original,CharSequence replacement)
trim() 去掉起始和结尾的空格
valueOf() 转换为字符串
toLowerCase() 转换为小写
toUpperCase() 转换为大写
length() 取得字符串的长度
例:
char chars[]={’a',’b’.’c'};
String s=new String(chars);
int len=s.length();
charAt() 截取一个字符
例:
char ch;
ch=”abc”.charAt(1);
返回值为’b’
getChars() 截取多个字符
void getChars(int sourceStart,int sourceEnd,char target[],int targetStart)
sourceStart 指定了子串开始字符的下标
sourceEnd 指定了子串结束后的下一个字符的下标。因此,子串包含从sourceStart到sourceEnd-1的字符。
target 指定接收字符的数组
targetStart target中开始复制子串的下标值
例:
String s=”this is a demo of the getChars method.”;
char buf[]=new char[20];
s.getChars(10,14,buf,0);
getBytes()
替代getChars()的一种方法是将字符存储在字节数组中,该方法即getBytes()
例:
String s = “Hello!你好!”;
byte[] bytes = s.getBytes();
toCharArray()
例:
String s = “Hello!你好!”;
char[] ss = s.toCharArray();
equals()和equalsIgnoreCase() 比较两个字符串
regionMatches() 用于比较一个字符串中特定区域与另一特定区域,它有一个重载的形式允许在比较中忽略大小写。
boolean regionMatches(int startIndex,String str2,int
str2StartIndex,int numChars)
boolean
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
2008 年 6 月 24 日
原文地址: http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0806wangys/
本文介绍 IBM FileNet P8 4.0 Platform 提供的 Content Java API。首先对 FileNet P8 Content Engine 和 API 进行概要介绍, 并说明了一些基本概念,随后详细介绍了 FileNet Content Engine提供的基于 EJB ......
public class MyEnumTestMain {
public enum MyenumTest{red,blue,green,black}//定义枚举类型
public static void main(String[] args) {
MyenumTest mt = MyenumTest.red;//red相当于枚举的静态属性
switch(mt){
case red:
System.out.println("red");
break;
case blue:
......
/**
* 描述:数据库初始化基本类
*
* @作者 王群
* @创建日期 2010-04-08
* @修改人 xxx
* @修改日期 xxx
* @检查人 xxx
* @检查日期 xxx
*/
import java.sql.SQLException;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.oumasoft.bstmanage.ibatis.SqlMapConfig;
import com.oumasof ......