String不像int或float, 它是参考类型。
final类型, 不能被继承,String is a Reference Type,Defined in java.lang package马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
常用方法:length()String greeting = “Hello”;int n = greeting.length();//is 5charAt(n)(取某个位置字符)char first = greeting.charAt(0);char last = greeting.charAt(4);substring()(取子字符串)String s = greeting.substring(0,3);//from 0 inclusive to 3 exclusiveConcatenation(链接)String a = greeting + “ world!”+ 2009;Equality(don’t use ==)(测试是否相等)String s = “Hello”; s.equals(greeting);“Hello”.equalsIgnoreCase(“hello”);(忽略大小写的测试相等)本章源码例子:public class Test {public static void main(String args[]) {String letters = “abcdefghijklabcdefghijkl”;/*这里讲讲阅读源代码,control点击进入方法*/System.out.println(“‘c’在第” + letters.indexOf(‘c’) + “个”);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)