博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
String
阅读量:6250 次
发布时间:2019-06-22

本文共 3711 字,大约阅读时间需要 12 分钟。

char charAt(int index)  

return the value at the index     

String s = "Hello world";System.out.println(s.charAt(0));    //Hs = "中国";System.out.println(s.charAt(1));   //国

int compareTo(String other)  

returns a negative value if the string comes before other in dictionary order, a positive

value if the string comes after the other, or 0 if the strings are equal

String s1 = new String("a");        String s2 = new String("a");        // compare the content instead of address        System.out.println(s1.compareTo(s2));    // 0,         String s3 = new String("b");        System.out.println(s1.compareTo(s3));    //-1
View Code

boolean equals(Object other)

return true if string equals other, only true when other is a string and the content is equals string

boolean equalsIgnoreCase(String other)

return true if the string equals other,except the upper/lowercase distinction

boolean startsWith(String prefix)

boolean endsWith(String suffix)

return true if the string starts/ ends with prefix/suffix

int indexOf(String str)

int indexOf(String str, int fromIndex)

return the start_index of the fisrt substring equals to the string str, or -1 if str not in this string,

boolean contains(CharSequence str)

Returns true if and only if this string contains the specified str

String s1 = new String("_hello world hello java");String s2 = "hello";int index = s1.indexOf(s2);  // 1int nextIndex = s1.indexOf(s2, index+1);  //13
View Code

int lastIndexof(str, int fromIndex)

String s1 = new String("_hello world hello java");        String s2 = "hello";        int index = s1.lastIndexOf(s2);  // 13        int nextIndex = s1.lastIndexOf(s2, index - 1 );  //1
View Code

int lengh()

String substring(int beginIndex, int endIndex)

String toLowerCase()

String toUpperCase()

String replace(CharSequence oldString, CharSequence newString)    //just take the CharSequence as String

String trim()    // eliminate all leading and tailing whitespace

String s1 = new String("Abc");        String upper = s1.toUpperCase();  // ABC        String lower = s1.toLowerCase();  // abc        int length = s1.length();   // 3        String newString = s1.replace("b", "2");  // A2c                String s2 = "   haha    ";        String trim = s2.trim();   // haha        String subStr = s1.substring(0, 2);  // Ab [0,2)
View Code

 

String join(CharSequence delimiter, CharSequence...elements)  // static

return a new string joining all elements with the given delimiter

char[] toCharArray()

Converts this string to a new character array

String s1 = new String("中国");String s2 = String.join("#", "a","b", "c"); //  a#b#cchar[] arr =  s1.toCharArray();    // [中, 国]
View Code
 

static  format( format, ... args)

Returns a formatted string using the specified format string and arguments.

Format String Syntax google

all the method above return the new String, cause the String is unmutable

String replaceAll ( regex,  replacement)     // regex 正则语法

String[] split( regex)

Splits this string around matches of the given regular expression.

boolean matches( regex)

Tells whether or not this string matches the given regular expression.

String regex = "hello";        String s = "hello jime sshello mm hellosdfs";        String s2 = s.replaceAll(regex, "H");  // H jime ssH mm Hsdfs                String s3 = "192.168.0.21";        regex = "\\.";        String[] strArr = s3.split(regex);  // [192, 168, 0, 21]        s3 = "abc@xxx.com";        regex = "[\\w]+@[\\w]+\\.com";          System.out.println(s3.matches(regex));   // true
View Code

static String valueOf(int i);    // also can be float double byte...

Returns the string representation of the int argument.

String s = String.valueOf(100);   //100  数字转字符串

 

转载于:https://www.cnblogs.com/YKang/p/7273329.html

你可能感兴趣的文章
python类型转换、数值操作
查看>>
关于Scalability的一些思考与疑问
查看>>
mongodb step by step
查看>>
一句话一个点
查看>>
深入浅出事件流处理NEsper(二)
查看>>
技术人生:如何做非正式的交流
查看>>
利用共享内存和信号灯集实现进程间同步一例
查看>>
类的基础
查看>>
Sql Server系列:使用Transact-SQL编程
查看>>
新增题目功能模块总结
查看>>
三、mono for android 学习:参考书籍
查看>>
javascript练习:8-10事件与this运算符
查看>>
Linux下SVN部署/安全及权限配置,实现web同步更新
查看>>
PHPSPY2013
查看>>
Android学习笔记(四)时钟、时间
查看>>
SQL SERVER 查询性能优化——分析事务与锁(二)
查看>>
动画实现实现上下滚动的TextView
查看>>
HDU-4461 The Power of Xiangqi 签到题
查看>>
方法线程SwingWorker的用法
查看>>
hdu 4313(类似于kruskal)
查看>>