Java中Arrays类、基本类型包装类

Arrays类:

       概述:针对数组进行操作的工具类。提供了排序,查找等功能。
       成员方法
              public static String toString(int[] a):把数组转成字符串
              public static void sort(int[] a):对数组进行排序(源码为快速排序)
              public static int binarySearch(int[] a,int key):二分查找
基本类型包装类:
       将基本数据类型封装成对象的好处在于可以在对象中定义更多的功能方法操作该数据。
       常用的操作之一:用于基本数据类型与字符串之间的转换。
       基本类型和包装类的对应:
              byte                    Byte
              short                   Short
              int                        Integer
              long                     Long
              float                     Float
              double                 Double
              char                     Character
              boolean               Boolean
       Integer类
              概述:Integer类在对象中包装了一个基本类型int的值;该类提供了多个方法,能在int类型和String类型之间互相转换,还提供了处理int类型时非常有用的其他一些常量和方法。
               构造方法:
                      public Integer(int value)
                      public Integer(String s)
               常用的基本类型转换
                      public static String toBinaryString(int i) (二进制)
                      public static String toOctalString(int i) (八进制)
                      public static String toHexString(int i) (十六进制)
                十进制到其他进制
                       public static String toString(int i, int radix)
                 其他进制到十进制
                       public static int parseInt(String s, int radix)
                 JDK1.5以后,简化了定义方式
                        Integer x = new Integer(4);可以直接写成Integer x = 4; //自动装箱。
                        x = x+5; //自动拆箱。通过IntValur方法。
                        注意:在使用时,Integer x = null;上面的代码就会出NullPointerException

/*
 * int ----- String
 * String ----- int
 * 
 * */
public class IntegerDemo {
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		
		//int --- String
		int num = 100;
		//方式1
		String s1 = "" + num;
		System.out.println("s1:"+s1);
		//方式2
		String s2 = String.valueOf(num);
		System.out.println("s2:"+s2);
		//方式3
		// int --- Integer --- String
		Integer i = new Integer(num);
		String s3 = i.toString();
		System.out.println("s3:"+s3);
		//方式4
		//public static String (int i)
		String s4 = Integer.toString(num);
		System.out.println("s4:"+s4);
		
		System.out.println("---------");
		
		//String --- Integer --- int
		String s = "100";
		//方式1
		//public int intValue()
		Integer ii = new Integer(s);
		int x = ii.intValue();
		System.out.println("x:"+x);
		//方式2
		//public static int parseInt(String s)
		int y = Integer.parseInt(s);
		System.out.println("y:"+y);
		
	}
}
---------------------------------------------------------------------
结果:

s1:100
s2:100
s3:100
s4:100
---------
x:100
y:100

         Character类
                概述:Character类在对象中包装一个基本类型char的值;此外,该类提供了几种方法,以确定字符的类别(小写字母,数字,等等),并将字符从大写转换成小写,反之亦然
                构造方法:
                       public Character(char value)
                常用方法:
                       public static boolean isUpperCase(char ch):判断给定的字符是否是大写字符
                       public static boolean isLowerCase(char ch):判断给定的字符是否是小写字符
                       public static boolean isDigit(char ch):判断给定的字符是否是数组字符
                       public static char toUpperCase(char ch):把给定的字符转化为大写字符
                       public static char toLowerCase(char ch):把给定的字符转化为小写字符


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值