• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
旧街古巷〃雨未停
每天进步一点
博客园    首页    新随笔    联系   管理    订阅  订阅

java之包装类型

/**字符串转化为基本类型xx.parsexx*/
String s = "12";
int a = Integer.parseInt(s);//字符串转化为整形
System.out.println(a);
Double b = Double.parseDouble(s);//字符串转化为双精度
/**基本类型转化为字符串valueOf(a) */
String str = String.valueOf(a);
System.out.println(str);
Integer i = new Integer(2);
Integer j = new Integer(2);
System.out.println(i==j);
Integer i1 = 3;
Integer j1 = 3;
System.out.println(i1 ==j1);
*******************************************
Integer i2 = 128;
Integer j2 = 128;
//基本数据类型是放在栈里的,包装类型定义的大于127,相当于new了一个对象,放在了堆里,==比较的地址,所以是false,用equals比较内容,则为true;
//Double,float定义的不会放在常量池,而是放在堆里的,所以地址不一样的
System.out.println("****分割*****");
Double i3 = 5.0;
Double j3 = 5.0;
System.out.println(i3 == j3);
System.out.println(i3.equals(j3));
Integer i4 = 128;
Integer j4 = 128;
System.out.println(j4.hashCode());
Boolean i5 = true;
Boolean j5 = false;
System.out.println(i5.hashCode());//布尔类型则转换ASCII
System.out.println(j5.hashCode());
//每一个类都具有的方法1:hashCode();2:equals();3:toString

***************************************************

Vector v = new Vector();
int a = 3;
v.addElement(a);
v.addElement("hello");
v.addElement(true);
System.out.println(v.size());
System.out.println(v.get(1));
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i));

}
for (Object o : v) {//o取出数组每个数,v为数组
System.out.println(o);
}

*********************************************************

Date date = new Date();
System.out.println(date.getTime());
//时间格式化;
SimpleDateFormat format = new SimpleDateFormat("yyyy年-MM月-dd日 HH :mm:ss:SSS a E");
System.out.println(format.format(date));

/**************************************************/
Calendar calendar = Calendar.getInstance();//获取日历实例
Date date1 = calendar.getTime();
calendar.setTime(date1);;
calendar.set(Calendar.DAY_OF_MONTH, 8);

System.out.println("时间日设置为8后,时间是"+calendar.getTime());

//修改当前日期,日历里的月份是从0-11月;
//添加月份date1.add(date1.MONTH,2);

posted @ 2017-06-14 15:26  旧街古巷〃雨未停  阅读(81)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3