javaString常用方法

来源:互联网 发布:php显示图片缩略图 编辑:程序博客网 时间:2024/06/04 21:33

String类型常用方法:

StringBuffered 常用方法:


包装类以及基本类型:


以Integer包装类为例:

Integer包装类的构造方法:



Integer常用方法:


其中: parseInt(String s)  valueOf(String s)   toString()是常用的方法

====================================================================================

自动装箱和手动装箱就是把基本类型变为包装类使其具有对象的性质:


自动拆箱和手动拆箱就是把包装类变为基本类型:



=============================================================================================

基本类型转换为字符串有三种方法:

1. 使用包装类的 toString() 方法

2. 使用String类的 valueOf() 方法

3. 用一个空字符串加上基本类型,得到的就是基本类型数据对应的字符串

public static void main(String[] args) {// TODO Auto-generated method stub            int   a=12;            Integer b=a;            String c=b.toString();            String c2=a+"";            String c3=String.valueOf(a);
            String c4=String.valueOf(b);
}
=============================================================================

String类型转变为基本类型:

public static void main(String[] args) {// TODO Auto-generated method stub            int   a=12;          String s="123";          a=Integer.parseInt(s);//返回的是int类型的数据          a=Integer.valueOf(s);//在这里valueOf()返回的是Integer类型的对象使用自动拆箱变为了int型          System.out.println(a);                      }
==============================================================================================


                                             
0 0