Byte类的测试

/**
 *<p>项目名称:  Java</p>
 *<p>文件名称:  ByteTest</p>
 *<p>版权所有:  版权所有(C)2008-2010</p>
 *<p>公    司:   

 *<p>编写日期: 2008-7-9上午03:36:46</p>
 *<p>作    者:  huangtao</p>
 */

 

/**
 * @author huangtao
 *
 */
public class ByteTest
{
 public static void main(String[] args)
 {
  //声明byte对象
  byte a11 = Byte.MAX_VALUE;
  byte b11 = Byte.MIN_VALUE;
  int c11 = Byte.SIZE;
  System.out.println(a11+"_"+b11+"_"+c11);
  byte a = 127;
  String b = "121";
  Byte b1 = new Byte(a);
  Byte b2 = new Byte(b);
  
  //获取byte值
  System.out.println(b1.byteValue());
  System.out.println(b2.byteValue());
  System.out.println(b1.compareTo(b2));
  System.out.println(b2.compareTo(b1));
  Byte b3 = Byte.decode(b);
  System.out.println(b3.byteValue());
  System.out.println(b1.equals(b2));
  System.out.println(b1.longValue());

  byte MA = Byte.MAX_VALUE;
  byte MI = Byte.MIN_VALUE;
  int between = MA-MI;
  
  //获取byte值和对应的hash码
  byte[] pb = new byte[MA];//存储正数的空间
  byte[] nb = new byte[0-MI];//存储负数的空间
  byte[] result = new byte[between];//正数和负数的所在的数组
  for(int i = MI , j = 0 ; i<0 ; i++ , j++)
  {
   nb[j] = (byte) i;
   System.out.println("负数1:"+i+"哈希码"+new Byte(nb[j]).hashCode());
  }
  for(int i = 0 , j = 0 ; i<MA ; i++ , j++)
  {
   pb[j] = (byte) i;
   System.out.println("正数2:"+i+"哈希码"+new Byte(pb[j]).hashCode());
  }
  
  //数组复制
  System.arraycopy(nb , 0 , result , 0 , nb.length);
  System.arraycopy(pb , 0 , result , nb.length , pb.length);
  for(int i = 0 ; i<result.length ; i++)
  {
   System.out.println("所有的数3:"+result[i]+"哈希码"+new Byte((byte) i).hashCode());
  }
  
  //获取byte值
  String str1 = "1";
  String str2 = "24";
  String str3 = "1";
  System.out.println(Byte.parseByte(str1));
  System.out.println(Byte.parseByte(str2));
  System.out.println(Byte.parseByte(str3 , 2));
  System.out.println(Byte.parseByte(str3 , 8));
  System.out.println(Byte.parseByte(str3 , 10));
  System.out.println(Byte.parseByte(str3 , 16));
  
  //获取Byte对象
  Byte bb1 = Byte.valueOf(Byte.parseByte(str1));
  Byte bb2 = Byte.valueOf(Byte.parseByte(str2));
  Byte bb3 = Byte.valueOf(Byte.parseByte(str3));
  System.out.println(bb1.byteValue());
  System.out.println(bb2.byteValue());
  System.out.println(bb3.byteValue());

  Byte bb41 = Byte.valueOf(str1 , 2);
  Byte bb42 = Byte.valueOf(str1 , 8);
  Byte bb43 = Byte.valueOf(str1 , 10);
  Byte bb44 = Byte.valueOf(str1 , 16);
  System.out.println(bb41.byteValue());
  System.out.println(bb42.byteValue());
  System.out.println(bb43.byteValue());
  System.out.println(bb44.byteValue());

 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值