我想将Set的第一个元素称为“ set”。这时,内容设置为= [“ 1”,“ 2”] ...当我运行以下代码时,它在iter.next()中返回“ 2”,他有可能首先返回“ 1” ”,然后在下一个循环“ 2”中?

//Remove duplicates from array
Set set= new HashSet(Arrays.asList(leveranciers));

Iterator iter = set.iterator();

while (iter.hasNext()) {

    //for (Iterator it = set.iterator();it.hasNext();){
    PdfPTable table = GetTable(""+ iter.next());
    byte[] pdf = wdThis.wdGetAchatsIndirectController().GetPDFFromFolder("/intranetdocuments/docs/AchatsIndirect", table);
    wdThis.wdGetAchatsIndirectController().PrintPDF(pdf);
}

最佳答案

好吧,HashSet不会保留插入顺序。如果需要,请使用LinkedHashSet。并且请使用参数化版本。

10-07 19:42
查看更多