0
에서 문자열 값과 객체 유형의 값을 구분하는 ArrayList의 문자열 값과 SongInfoModel (객체) 값이 포함되어 있습니다.내가 ArrayList에에게</p> <p><code>private ArrayList<Object> myList = new Arraylist<>()</code></p> <p>이 어떻게 객체 ArrayList를
이 두 개를 각각의 arraylists로 가져 오는 방법은 무엇입니까?
private ArrayList<SongInfoModel> songList = new Arraylist<>()
private ArrayList<String> path= new Arraylist<>()
나는 아래의 코드를 사용하고 있지만,이 나는 이것이 noobish 질문 알고 문
for(Object ob: myList){
if(ob instanceof SongInfoModel) {
songList.add(ob); //error
}else if(ob instanceof String){
path.add(ob); //error
}
}
을 "추가"나에게 오류를주고 있지만, 도와주세요!
그것은 수도 게시 (또는 당신이 이렇게 아직하지 않은 경우 읽기) 오류를 도움이됩니다. 또한 목록의 이름이 올바르게 지정되어 있습니까? 'SongList'를 한 번,'songList'를 두 번 사용합니다. 비슷하게,'PathName'과'path'는 상호 교환 적으로 같습니다. – lucidbrot
instanceof 다음에 객체를 형 변환 할 수 있습니다 – jeprubio