第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中的日歷順序

java中的日歷順序

達令說 2021-10-13 10:34:48
公共類 FileDAO 擴展 DaoBase 實現(xiàn) ITreeDao {File rootDirectory = null;public FileDAO(File rootDirectory) {    if(!rootDirectory.exists()){        throw new IllegalArgumentException("Directory " + rootDirectory.getAbsolutePath() + " doesn't exist");    }    this.rootDirectory = rootDirectory;}protected ITreeNode readRoot(ITree tree) {    tree.setRoot(readNode(this.rootDirectory));    TreeSorter.sortById(tree.getRoot());    return tree.getRoot();}protected Set readChildren(ITreeNode parentNode) {    Set children = new HashSet();    File parentDir = (File) parentNode.getObject();    String[] files = parentDir.list();    if(files == null) return children;    for(int i=0; i<files.length; i++){        File childFile = new File(parentDir.getAbsolutePath() + File.separator + files[i]);        ITreeNode child = readNode(childFile);        child.setParentId(parentNode.getId());        if(!childFile.exists()) continue;        children.add(child);    }    // Sort here    TreeSorter.sortById(parentNode);    return children;}protected Set readGrandChildren(ITreeNode parentNode) {    Set grandChildren = new HashSet();    Iterator children = parentNode.getChildren().iterator();    while(children.hasNext()){        ITreeNode child = (ITreeNode) children.next();        grandChildren.addAll(readChildren(child));    }    return grandChildren;}protected ITreeNode readNode(File file){    if(!file.exists()) return null;    ITreeNode node = null;    String childType = file.isDirectory() ? "directory" : "file";    if(childType.equals("file")){        node = new TreeNode(file.getAbsolutePath(), "<a href=\"openPdf.jsp?fileName=" + file.getAbsolutePath() + "\" target=_blank>" + file.getName() + "</a>" , childType);    }else{        node = new TreeNode(file.getAbsolutePath(), file.getName() , childType);    }    node.setObject(file);    return node;}}在這段代碼中,我在readGrandChildren()方法上面臨一個問題。就像那里我得到日歷月份的升序,但我想顯示日歷順序,如 Jan、Feb、Mar.....Dec。請任何人都可以幫助我嗎?
查看完整描述

1 回答

?
回首憶惘然

TA貢獻1847條經(jīng)驗 獲得超11個贊

使用 TreeSet,通過實現(xiàn) Comparator 接口并提供反向排序邏輯,最后使用 Collection 接口的 addAll() 方法將 HashSet 的所有元素添加到 TreeSet。


// using Comparator constructor argument of TreeSet

TreeSet < String > ts = new TreeSet < String > (new Comparator < String > () {


 @Override

 public int compare(String o1, String o2) {

  // reverse sorting logic

  return o2.compareTo(o1);

 }

});


// add HashSet elements to TreeSet

ts.addAll(grandChildren);


System.out.println("\n\n\nAfter Sorting : Descending order\n");


// Iterating using Iterator

Iterator < String > ascSorting = ts.iterator();

while (ascSorting.hasNext()) {

 System.out.println(ascSorting.next());

}


查看完整回答
反對 回復(fù) 2021-10-13
  • 1 回答
  • 0 關(guān)注
  • 141 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號