java遍历对象
JDK1.4中
Map map = new HashMap();
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
JDK1.5中,应用新特性For-Each循环
Map m = new HashMap();
for(Object o : map.keySet()){
map.get(o);
}
返回的 set 中的每个元素都是一个 Map.Entry 类型。
private Hashtable<String, String> emails = new Hashtable<String, String>();
另外 我们可以先把hashMap 转为集合Collection,再迭代输出,不过得到的对象
//方法一: 用entrySet()
Iterator it = emails.entrySet().iterator();
while(it.hasNext()){
Map.Entry m=(Map.Entry)it.next();
logger.info("email-" + m.getKey() + ":" + m.getValue());
}
// 方法二:jdk1.5支持,用entrySet()和For-Each循环()
for (Map.Entry<String, String> m : emails.entrySet()) {
logger.info("email-" + m.getKey() + ":" + m.getValue());
}
// 方法三:用keySet()
Iterator it = emails.keySet().iterator();
while (it.hasNext()){
String key;
key=(String)it.next();
logger.info("email-" + key + ":" + emails.get(key));
}
// 方法五:jdk1.5支持,用keySEt()和For-Each循环
for(Object m: emails.keySet()){
logger.info("email-" + m+ ":" + emails.get(m));
}
Map aa = new HashMap();
aa.put("tmp1", new Object());
//追加 替换用同样的函数.
aa.remove("temp1");
//删除
for (Iterator i = aa.values().iterator
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
Annotations
Annotations是J2SE 5.0引入的新语言特性。通常, Annotations允许开发者用一种跟运行代码无关的次要信息来标注类,方法以及成员。这样就可以使用类似评价的 Annotations,比如“好方法”、“坏方法”,或者更详细一些,“不推荐的方法”、“覆写的方法&rdq ......
//获取数据库数据返回list
public List queryAll(int fcateId) {
List list = new ArrayList();
String sql = "select * from g_Account where fCateID=? order by fCode";
Connection con = SqlHelp.getConn();//获得连接,sqlhelp自己写的工具类
PreparedStatement pst = null;
ResultSet rs = null;
......
核心思想:把含main方法的入口类添加到MANIFEST.MF文件中。
步骤:
假设有两个类文件要打包,它们分别属于不同的package。
package com.test.jar;
import java.awt.*;
import javax.swing.*;
public class Jar extends JFrame
{ ......