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
相关文档:
66. EJB容器提供的服务
主要提供声明周期管理、代码产生、持续性管理、安全、事务管理、锁和并发行管理等服务。
67. EJB规范规定EJB中禁止的操作有哪些?
1.不能操作线程和线程API(线程API指非线程对象的方法如n ......
URL的openConnection()方法将返回一个URLConnection对象,该对象表示应用程序和 URL 之间的通信链接。程序可以通过URLConnection实例向该URL发送请求、读取URL引用的资源。
通常创建一个和 URL 的连接,并发送请求、读取此 URL 引用的资源需要如下几个步骤:
(1)通过调用URL对象openConnection()方法来创建URLConnectio ......
通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。一般有两种方案:即优化代码或更改设计方法。我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能。而一个设计良好的程序能够精简代码,从而提高性能。
下面将提供一些在JAVA程序的设计和编码中,为了能够 ......
请参见上一篇文章,登录MSN协议
具体Java实现:
命令序列:<<代表发送,>>代表结果
1.连接DS(Dispatcher Server),得到NS(Notification Server)
<<VER 1 MSNP18 CVR0
>>VER 1 MSNP18
<<CVR 2 0x0804 winnt 5.1 i386 MSNMSGR 14.0.8089.0726 msmsgs yourAccount
>>CVR 2 14.0.8089 ......
java生成验证码
有很多种方式,在网上也有很多代码,但是那些生成的效果,感觉都不是特别好,所以我在他们的基础上改良了一些。
但能还可以用jmagick ,生成很多很炫的验证码。过两天研究下。先把最近改的这个发布下供朋友们参。
可以先看看样例。最近在做这个网站。大家有兴趣可以叫交流。约会360 网址: www.yue ......