码迷,mamicode.com
首页 > 其他好文 > 详细

String类扩展

时间:2016-10-09 06:58:52      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

        String s1=new String("fsdfsd");
        String s2=new String("fsdfsd");
        String a1="fsdfsd";
        String a2="fsdfsd";
        System.out.println(a2==a1);//true
        System.out.println(s1==a1);//false
        System.out.println(s1.equals(s2));//true
        System.out.println(s1.equals(a1));//true
        System.out.println(a1.equals(s1));//true

结论:只用equals方法

public boolean compareTo(String s)比较方法

public boolean contains(String s)是否在里面

public String substring(int a,intb)截取a到b-a

public String trim()去掉串前面和后面的空格

String a1="234342";
int a=Integer.parseInt(a1);和javascript差不多的方法

对应的String b=String.valueOf(a);

String 写成数组的两个方法

String s="1234567";
        char a[]=new char[5];
        s.getChars(1, 5, a, 0);

s.getchars(a,b,数组,offset) a那个开始,b到b-1的位置上,offset 在数组那个位置开始

public char[] String.toCharArray()

数组写成String

String(char a[],int offset,int lentgh)

String类扩展

标签:

原文地址:http://www.cnblogs.com/vhyc/p/5940582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!