-1

I have filled in an ArrayList of strings with suppliernumbers. This list contains duplicates values so I want to delete them with the HashSet.

I get following error: Invalid expression as statement On line => Set set = new HashSet(leveranciers); (Set underlined) Any idea why?

String[] leveranciers = new String[wdContext.nodeShoppingCart().size()];

for(int i = 0; i<wdContext.nodeShoppingCart().size(); i++){

      String productnumber = wdContext.nodeShoppingCart().getShoppingCartElementAt(i).getMatnr()

      wdThis.wdGetAchatsIndirectController().GetDetails(productnumber, "NL");
      leveranciers[i] = wdContext.currentEt_DetailsElement().getLifnr();
}

 //Remove duplicates from array
        Set<String> set = new HashSet<String>(leveranciers);
        set.toArray(new String[0]);


for(int y = 0; y<set.size();y++){
    PdfPTable table = GetTable(set[y]);
    byte[] pdf = wdThis.wdGetAchatsIndirectController().GetPDFFromFolder("/intranetdocuments/docs/AchatsIndirect", table);
    wdThis.wdGetAchatsIndirectController().PrintPDF(pdf);
}
4

1 回答 1

2

HashSet 没有接受数组的构造函数。查看 HashSet 文档。 http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html

您可以使用Arrays.asList以下方法实现您的目标:

final String[] strings = new String[] {"ab", "ba", "ab"};
final Set<String> set = new HashSet<String>(Arrays.asList(strings));
于 2014-04-16T15:31:17.247 回答