E 'strano: A è un set e B è un insieme di insiemi:Come rilevare se un Set di Set contiene un altro Set?
Set <String> A=new HashSet<String>();
Set <Set<String>> B=new HashSet<Set<String>>();
ho aggiunto le cose a loro e l'uscita del
System.out.println(A)
è:
[evacuated, leave, prepc_behind]
e l'output di
System.out.println(B)
.210
è:
[[leave, to, aux], [auxpass, were, forced], [leave, evacuated, prepc_behind]]
come si può vedere, terzo elemento della serie B è uguale per impostare A. Quindi ipoteticamente
if(B.contains(A)){...}
deve restituire vero, ma a quanto pare non è così. Qual è il problema?
piu 'dettagli:
Pattern pattern = Pattern.compile("(.*?)\\((.*?)\\-\\d+,(.*?)\\-\\d+\\).*");
for (int i = 0; i < list.size(); i++) {
Set <String> tp = new HashSet<String>();
Matcher m = pattern.matcher(list.get(i).toString());
if (m.find()) {
tp.add(m.group(1).toLowerCase());
tp.add(m.group(2).toLowerCase());
tp.add(m.group(3).toLowerCase());
}
B.add(tp);
}
Set <String> A=new HashSet<String>();
A.add("leave");
A.add("evacuated");
A.add("prepc_behind");
System.out.println(A);
if(B.contains(A)){
System.out.println("B contains A");
}
Come stai aggiungendo gli elementi? Perché "B.taintains (A)" restituisce il vero per me. –
Funziona come previsto (vale a dire, restituisce true) anche per me. –
Ho un ciclo for che continua ad aggiungere i set a B usando: B.add (tp); tp è un set. – Marcus