今天继续个人作业2,
对于获取的数据的处理:
public Map<String,Integer> getallmax() { String sql="select * from cvpr"; Map<String, Integer>map=new HashMap<String, Integer>(); Map<String, Integer>sorted=new HashMap<String, Integer>(); Connection con=null; Statement state=null; ResultSet rs=null; try { con=Util.getConnection(); } catch (SQLException e3) { // TODO Auto-generated catch block e3.printStackTrace(); } try { state=con.createStatement(); rs=state.executeQuery(sql); while(rs.next()) { String keywords=rs.getString("keywords"); String[] split = keywords.split(","); for(int i=0;i<split.length;i++) { if(map.get(split[i])==null) { map.put(split[i],0); } else { map.replace(split[i], map.get(split[i])+1); } } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Util.close( con, state,rs); sorted = map .entrySet() .stream() .sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) .collect( Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new)); return sorted; }