English 中文(简体)
浏览代码的硬盘或哈希姆普?
原标题:StringBuffer or HashMap for appending codes?
  • 时间:2010-09-24 07:07:25
  •  标签:
  • java

<>StringBuffer or HashMap

这是修订守则的最佳途径,也使业绩更好。

StringBuffer sql = new StringBuffer();
DBDatabase db = UTIL.getDatabase();
sql.append("SELECT I.FLDCODE, I.FLDDESCR, I.FLDWORKPHON FROM ");
sql.append(db.getSchema());
sql.append("TRNINSTR I, ");
sql.append(db.getSchema());
sql.append("TRNCRSIN C WHERE C.FLDCOURSE = ? AND C.FLDINSTRUCT = I.FLDCODE AND (I.FLDINACTIVE IS NULL OR I.FLDINACTIVE <>  y ) ORDER BY C.FLDSEQUENCE");
DBPreparedStatement stmt = new DBPreparedStatement(db, sql, "TrainPage.getInfoInstrList");
stmt.setString(1, courseType);
DBResultSet rs = stmt.executeQuery();
stmt.close();
最佳回答

问题不明确(“适用守则”? “HashMap” ,但我假定,你正在问,如何更有效地建立优势。

一般来说,强硬公司比“斯特林贝”公司更有效率,因为后者的方法是同步的,这只是一个read化物体的不必要的间接费用。

但是,现在的问题是,使用“StingBuilder”是否比单纯的“强调”更为有效。 答案是“取决于”。

如果你做许多不同的分类,那么“长者”一般会更快。

String s = "";
for (int i = 0; i < 1000; i++) {
    s += "X";
}

如果你以某种方式做所有分类,那么它可能不会改变:

String s = "Hi " + name + ". It is a might fine " + day + ".";

这是因为, Java编者将把这一条变成法典,从而形成一个强硬体,进行一系列的<条码>应用<>/代码>电话。

然而,这略为过于简单化。 一方面,如果您的申请能够方便地计算最后指令的长度,那么,通过分配拥有适当初步能力的建筑商,你能够利用“斯特林堡”来提高绩效。 而另一方面,汇编者将先评估“强硬字面”的分类,这样就可评估。

String s = "Hi " + "mom" + ".  is a might fine " + "tuesday" + ".";

较之:

StringBuilder sb = new StringBuilder();
sb.append("Hi ");
sb.append("mom");
sb.append(".  is a might fine ");
sb.append("tuesday");
sb.append(".");
String s = sb.toString();

但是,底线是 或许是t? 除非你做大量铺面的建筑,否则你的申请的总体执行情况将受到最小的影响。

问题回答

StringBuilder效果更好。 铭记这一缓慢部分是数据库的存取,而不是报表的编制。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...