String的属性和方法

String的属性和方法

package com.zzu.java.array;
public class TtString {
    /**
     * @author 程路超
     * @param args
     */
    public static void main(String[] args) {
        String string = "abcdefghijklmnopqrstuvwxyz郑州制造郑州";
        String s1 = "                ab   d                  ";
        String s2 = "adb";
        
        

 
        // string.charAt(index);//返回字符串中对应数组 "value[index]"下标的字符;
        // char c= string.charAt(33);
        // System.out.println(c);
        
        
        // string.codePointAt(index);//返回char类型的字符对应的编码值
        // int i=string.codePointAt(0);
        // System.out.println(i);
        
        
        // string.compareTo(anotherString);//比较两个字符串的大小 大于为正数 小于为负数 相等为0
        // ,考虑大小写,而且小写字母比大写字母大
        // System.out.println(s1.compareTo(s2));
        // System.out.println(s1.compareToIgnoreCase(s2));
        
        
        // string.concat(str);//连接字符串,但会创建一个新的字符串并返回 string+"新字符"
        // String ss=string.concat("新字符");
        // System.out.println(ss==string);
        // System.out.println(string);
        // System.out.println(ss);
        
        
        // string.contains("abc");//查询是否包含指定的字符串,返回布尔值
        // boolean ff=string.contains("abfc");
        // System.out.println(ff);
        
        
        // startWith以XXX开头 endsWith:以XXX结尾
        // boolean ff=string.startsWith("acbc");
        // boolean fs = string.endsWith("郑州");
        // System.out.println(fs);
        
        
        // equals:比较字符串的值,字符串重写了equals方法,将来我们的对象也可以重写equals
        // System.out.println(s1==s2);
        // System.out.println(s1.equals(s2));
        
        
        // hashCode:获取对象的哈希值,如果两个对象equals那么他们的hashcode一定相同,但hashcode相同不一定equals
        // System.out.println(s1.hashCode());
        // System.out.println(s2.hashCode());
        
        
        // getBytes获取字符串对应的字节数组,有可能产生乱码
        // byte b[]=string.getBytes();
        // for (int i = 0; i < b.length; i++) {
        // System.out.println(b[i]);
        // }
        
        
        // indexOf:返回当前字符串所在的索引值
        // int i=string.indexOf("cd");
        // System.out.println(i);
        //
        
        // length:返回当前字符串的长度
        // System.out.println(string.length());
        
        // replace:替换
        // String newstring = string.replace("abc", "oooooo");
        // System.out.println(newstring);
        
        // split:拆分字符串
        // String ss[]=string.split("uvw");
        // for (int i = 0; i < ss.length; i++) {
        // System.out.println(ss[i]);
        // }
        
        // substring:截取字符串 [1,5)
        // String news=string.substring(0,5);
        // String newstr=string.substring(1,string.length());
        // System.out.println(news);
        // System.out.println(newstr);
        
        // trim:去掉前后两端的空格
        // System.out.println(s1.trim());
        
        // toLowerCase  toUpperCase 转换为大小写
        // System.out.println(string.toLowerCase());//小写
        // System.out.println(string.toUpperCase());
        
        // valueOf 将 char 类型 的 字符 转换成 String 字符串
        //String ss = String.valueOf('a');


str.toCharArray();//字符串转成字符数组
 
    }
}
     
 

 

posted @ 2017-05-31 10:16 路迢迢 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值