今天做热词数量统计部分
public void sumreci() { String keys = null; Connection connection = DBUtil.getConn(); PreparedStatement preparedStatement=null; ResultSet rs=null; try { String sql = "select keywords from lunwen"; preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); while(rs.next()){ if(keys==null) {keys=(String)rs.getObject(1);} else {keys+=(String)rs.getObject(1);} } } catch (SQLException e) { e.printStackTrace(); } String arrays[]=keys.split(","); Map<String,Integer> map = new HashMap<String,Integer>(); for(int i=0;i<arrays.length;i++){ if(map.get(arrays[i])!=null){ map.put(arrays[i],map.get(arrays[i])+1); }else{ map.put(arrays[i],1); } } Set<String> keys1 = map.keySet(); Iterator<String> its = keys1.iterator(); int i=1; while(its.hasNext()){ String key = its.next(); Integer value = map.get(key); if(value>1){ //System.out.println(i+"元素"+key+" "+value); i++; } } }