String Fundamentals
来源:互联网 发布:怎么开通淘宝直播间 编辑:程序博客网 时间:2024/06/06 14:28
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
String s = “Hi Jim”;
String[] strs = s.split(” “);
1.Print
System.out.println(s);
2.Length
s.length() = 6;
strs.length = 2;
str[1].length() = 3;
3.Split string into string array, char array
String array
String[] strs = s.split(” “);
String[] strs = s.split(" "); for (String x : strs) System.out.println(x); System.out.println(strs.length);
The result is
HiJim2
Char Array
char[] c = s.toCharArray();
include blanks
4.The Nth char
S.charAt(3) = J
注意’ ’ 表示char 但 ” “表示String
5. Insert letters
- You can use StringBuffer > http://www.coderanch.com/t/390095/java/java/Insert-String
6. Replace letters
- Turn the String into a char[], replace the letter by index, then convert the array back into a String.
String myName = "domanokz";char[] myNameChars = myName.toCharArray();myNameChars[4] = 'x';myName = String.valueOf(myNameChars);
- You can overwrite a string, as follows:
String myName = "halftime";myName = myName.substring(0,4)+'x'+myName.substring(5); The result is : halfxime
7. String Concatenation
- Just use ‘+’, but time consuming > http://alvinalexander.com/blog/post/java/combine-two-strings
- Use StringBuilder and append
8. Character Manipulation
- Characeter.isLetter(char x) Character.isDigit(char x)
- Charaster.toLowerCase() Character.toUpperCase()
- isAlphanumeric(char x)
0 0
- String Fundamentals
- Firewall Fundamentals
- Firewall Fundamentals
- Silverlight Fundamentals
- WPF Fundamentals
- MPLS Fundamentals
- Application Fundamentals
- jQuery Fundamentals
- Application Fundamentals
- Application Fundamentals
- VBScript Fundamentals
- VBScript Fundamentals
- Application Fundamentals
- Application Fundamentals
- App Fundamentals
- MongoDB Fundamentals
- Application Fundamentals
- Application Fundamentals
- 深入理解观察者模式(二)
- 程序日志
- LeetCode 45. Jump Game II|贪心算法
- Android四大组件之一:Activity总结(下)
- PHP的继承方法如何获取子类名?
- String Fundamentals
- 【水水水】【洛谷 U4566】赛车比赛
- 视频App市场总结
- Spring笔记一 SpringInAction第二章(一):装配Bean(一)
- 【C语言】用递归实现字符串逆序的曲折之路
- 圆周卷积(circular convolution)
- swift 地图定位(五)指南针
- 基于memcached for java 实现通用分布式缓存和集群分布式缓存
- 扩展欧几里得noip2012同余方程