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 ......
Java面试中,最常被人问到的几个问题:
1. java.util.*包的UML结构图。
2. Vector和ArrayList、LinkedList区别 Hashtable 和 HashMap之间的区别
3. String、StringBuffer,StringBuilder之间区别。
--回答--
1.
Collection
|
|_List
| |_LinkedList
| | ......
------------------------------------------------------------------------------------------------
这几天主要是狂看源程序,在弥补了一些以前知识空白的同时,也学会了不少新的知识(比如 NIO),或者称为新技术吧。
线程池就是其中之一,一提到线程,我们会想到以前《操作系统》的生产者与消费者,信号量,同步控制 ......
问题1.
public static void append(String str){
str += " Append!";
}
public static void append(StringBuffer sBuffer){
sBuffer.append(" Append!");
}
public void test(){
String str = "Nothing";
append(str);
System.out.println(str);
StringBuffer sBuffer = new StringBuffer("Nothing" ......
1. 如何得到Java应用程序的可用内存?
答:如下代码实现取得总的内存大小和可用内存大小,并打印到控制台上
public class MemoryExp {
public static void main(String[] args) {
System.out.println("Total Memory"+Runtime.getRuntime().totalMemory());
System.out.println("Free Memory ......