Java LinkedHashSet backwards iteration

后端 未结 5 1872
执念已碎
执念已碎 2020-12-09 16:02

How can I iterate through items of a LinkedHashSet from the last item to the first one?

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 16:25

    This is another way:

    LinkedHashSet set = ...
    
    List list = new ArrayList<>(set);
    Collections.reverse(list);
    
    for( T item : list ){
       ...
    }
    

提交回复
热议问题