마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

arraylist 중복 제거가 안되요

0 추천
제가 지금 mediastore에서 값을 읽어와서 

리스트에 뿌르고 있습니다. 

근데 아티스트명에 따라 중복을 제거 하려고 하는데

어떻게 해야할까요 

String[] artistcolumns = {
      MediaStore.Audio.Media.ARTIST
    };
    
    cursor = null;
    cursor = getActivity().getContentResolver().query(
      MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, 
      artistcolumns, 
      null, 
      null, 
      null);
    
    while (cursor.moveToNext()){
     infoClass = new InfoClass(
       0,
       0,
         null,
         null,
         null,
       cursor.getString(cursor
         .getColumnIndex(MediaStore.Audio.Media.ARTIST)),
         null);     
     
     artistArray.add(infoClass);
     Collections.sort(artistArray, mComparator);
     mAdapter = new GroupCustomAdapter(getActivity(), artistArray);
     artistlist.setAdapter(mAdapter);
     mAdapter.notifyDataSetChanged();
    }
//    Log.e("------------","==== 배열" + artistArray);
    cursor.close();


array 형태는 

 public InfoClass(int _id, int data, String title, String name, String type, String artist, String album){
  this._id = _id;
  this.data = data;
  this.title = title;
  this.name = name;
  this.type = type;
  this.artist = artist;
  this.album = album;
 }

이런식으로 되어있습니다. 그중에 아티스트 부분만 쓴건데여 hash를 쓰든 

contains 를 쓰든 리스트를 다 뿌려줍니다.. 중복제거 하려면 어떻게 해야할까요

 

프리머니 (270 포인트) 님이 2015년 7월 31일 질문

1개의 답변

0 추천

방법이야 많을텐데.. 저의 경우 Set 을 사용해서 중복 제거를 하고 있습니다. 

TreeSet 같은 것으로  add 하면, 중복이 제거되서 add가 되기 때문에 TreeSet 데이터를 ArrayList로 변경하는 로직만 추가하여 이후 로직을 수행하면 되거든요..

 

익명사용자 님이 2015년 7월 31일 답변
제가 hashset을 써봤는데 중복삭제가 안되더라구요  treeset은 안써보긴 했는데...
...