javaSE--int和Integer

int 和 Integer 有什么区别?
int 是基本类型,Integer是引用类型,Integer是包装类,
Integer可以自动转换为int称为拆箱,int转换为Integer是自动装箱
int的默认值为0,Integer的默认值为null
Integer实际是对象的引用,当new一个Integer时,实际上是生成一个指针指向此对象;而int则是直接存储数据值 所以 Integer i = 100 ; int j=100;      i == j (false)
对于-128到127之间的数,会进行缓存,Integer i = 127时,会将127进行缓存,下次再写Integer j = 127时,就会直接从缓存中取,就不会new了
int 转换为 Integer 
int a=5;
Integer A=Integer.valueOf(a);
Integer到int:
Integer A=new Integer(5);
int a=A.intValue();
常遇到输出某种编码的字符,如 iso8859-1 等,请你讲讲如何输
出一个某种编码的字符串?
public static String translate (String str) {
        String tempStr ="";
        try {
        tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
        tempStr = tempStr.trim();//删除头尾空白符的字符串。
        }
        catch (Exception e) {
        System.err.println(e.getMessage());
        }
        return tempStr;
        }
    public static void main(String[] args) {
        System.out.println(translate("zha"));
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值