代码提升

1:

为了程序的健壮性

我们可能使用Integer.ValueOf(1)去代替newInteger(1);

 

public staticInteger valueOf(int i)返回一个表示指定的 int 值的 Integer 实例。如果不需要新的 Integer实例,则通常应优先使用该方法,而不是构造方法 Integer(int),因为该方法有可能通过缓存经常请求的值而显著提高空间和时间性能。  

 

2

if (result.size() > 0)  return true;

return  false;

 

我就写

 

return result.size() > 0;

 

3

最简单的"const".eqauls(variable)代替 variable.eqauls("const")

避免null pointexception

 

 

4

1.在连接字符串的时候尽量避免使用String= "str"+"str2";

而使用StringBuffer str= new StringBuffer("str");str.append("str2")代替

2.多使用PreparedStatement代替Statement这样可以避免在拼接字符串的时候出现

"select * fromtablename where col = '"+col+"'"单引号过多的情况


原文地址:https://www.cnblogs.com/allenzhaox/p/3201866.html