Java学习笔记:字符串

来源:互联网 发布:2012年3d开奖数据 编辑:程序博客网 时间:2024/06/08 12:15

1、数字(2)转换成固定长度(7)的字符串(0000002)原型:
DecimalFormat df = new DecimalFormat(“0000000”);
String id=df.format(2);
person1.Set_ID(person1.Get_birth()+id);
//此处也体现了字符串的连接方法:直接通过‘+’实现

2、字符串的截取:subString
String form=person2.Get_ID().substring(10, 17);
DecimalFormat df2 = new DecimalFormat(“0000000”);
String id2=df2.format(Integer.parseInt(form)+1);
person3.Set_ID(person3.Get_birth()+id2);

3、toString:当调用一个对象的引用的时候,时间上是调用的该对象的toString方法,在对象对应类中没有重写toString方法的话基本上都是调用的Object的toString方法。类名@对象哈希属性值:
getClass().getName()+”@”+Integer.toHexString(hashCode());

0 0