java中string与其他类型之间的互相转换
1.将Int,Float,Double,Long转换为String
String s = ""+i;
String s = String.valueOf(i);
String s = Integer.toString(i);
第一种方法:s = ""+i; //会产生两个String对象
第二种方法:s=String.valueOf(i); //直接使用String类的静态方法,只产生一个对象
第三种方法:效率最高?
2.将String转换为Int,Float,Double,Long
int i = Integer.parseInt(s);
int i = Integer.valueOf(s).intValue();
第一种方法:i=Integer.parseInt(s);//直接使用静态方法,不会产生多余的对象,但会抛出异常
第二种方法:i=Integer.valueOf(s).intValue();//Integer.valueOf(s) 相当于 new Integer(Integer.parseInt(s)),也会抛异常,但会多产生一个对象
3.将Date转换为String
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String s = format.format(date);
4.将String转换为Date
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse(s);
------------------------------------------------------------------------------------------------------------
public class TypeChange {
public TypeChange() {
}
//change the string type to the int type
public static int stringToInt(String intstr)
{
Integer integer;
integer = Integer.valueOf(intstr);
return integer.intValue();
}
//change int type to the string type
public static String intToString(int value)
{
Integer integer = new Integer(value);
return integer.toString();
}
//change the string type to the float type
public static float stringToFloat(String floatstr)
{
Float floatee;
floatee = Float.valueOf(floatstr);
return floatee.floatValue();
}
//change the float type to the string type
public
相关文档:
Impl
public class BaseDAOImpl extends HibernateDaoSupport implements IBaseDAO
//添加数据
this.getHibernateTemplate().save(achi);
//删除
this.getHibernateTemplate().delete(this.getById(achi));
//查询所有
return this.getHibernateTemplate().find("from Achievement a ......
1.列举出 10个JAVA语言的优势
a:免费,开源,跨平台(平台独立性),简单易用,功能完善,面向对象,健壮性,多线程,结构中立,企业应用的成熟平台, 无线应用
2.列举出JAVA中10个面向对象编程的术语
a:包,类,接口,对象,属性,方法,构造器,继承,封装,多态,抽象,范型
3.列举出JAVA中6个比较常用的包
Java. ......
学java也将近快两年的时间了,之前学过的东西自己感觉有点模糊,理论掌握的不是很透彻,有些问题解决的也不是很全面,为此在大学毕业前夕,想把知识好好的梳理一下,把自己对技术的疑点和一些研究心得写到csdn博客上。 ......
最近看到一个有意思的树形结构,为每个节点添加了lft
和
rgt
两个属性。这样查找该节点的子节点、
查找该节点所有父节点,就不用去递归查询,只需要用
between
、
and
语句就可以实现。下面以创建一个栏目树为例,以下是我的理解。
一般来讲,我们创建栏目树的时候,大多只需要一个外键parentid
来区分该节点 ......