오늘 저는 어제보다 훨씬 어리 석한 문제가 있습니다. 그러나 왜 내 코드가 작동하지 않는지 이해할 수 없습니다.List 및 ArrayList 제거 메서드가 작동하지 않습니다.
public class A{
List fileList;
public A(List fl){
fileList = new ArrayList<String>;
if(fl != null) {
fileList = fl;
}
}
public void removeFiles(List fl){
for(Object obj : fl) {
fileList.remove(obj.toString());
}
}
}
나는 심지어 Iterator
와 내가 웹에서 발견 된 모든 하나의 일을 시도하지만 파일이 제거되지 않은 및 오류 또는 예외가 온다 :
코드는 다음과 같습니다!
다른 사람 나는이 방법으로이 문제를 해결 한 경우 를 해결 좀 더 코드
public class CoordinationServer extends Activatable implements CoordinationSerInt
{
List<CoordObj> userList;
public int updateFileList(String username, List files, int option) throws RemoteException{
for (CoordObj anUserList : userList) {
if (anUserList.getUsername().equals(username)) {
if(option == 0){
anUserList.setFileList(files);
return 1;
}else if(option == 1){
anUserList.addFilesToList(files);
return 1;
}else if(option == 2){
anUserList.removeFiles(files);
return 1;
}
return 0;
}
}
return -1;
}
}
public class CoordObj implements Serializable
{
UserForUser userReference;
List fileList;
String username;
public CoordObj(UserForUser ur, List fl, String un) {
userReference = ur;
fileList = new ArrayList<String>();
if(fl != null)
fileList = fl;
username = un;
}
public void removeFiles(List fl){
this.fileList.removeAll(fl);
}
}
:
fileList.removeAll(Arrays.asList(fl.toArray()));
당신은'fileList.removeAll (FL)'도 아닌 구현 자신의 루프를 사용할 수 있어야합니다. [here] (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#removeAll (java.util.Collection)) 설명서를 참조하십시오. – Phylogenesis
@Phylogenesis : 또는'fileList.clear()'. – Brian
아직 아무것도 ... fileList.removeAll (fl)을 시도했지만 아무 것도 제거하지 못했습니다 .. – Irith