मैं सामग्री प्रदाता से संपर्क लाना हूँ की ArrayList से डुप्लिकेट तत्वों को दूर नहीं किया जा सकता और मैं इस प्रक्रिया मैं सफलतापूर्वक संपर्कों को लाने के लिए एक listview.In में उन्हें प्रदर्शित करने की आवश्यकता है, लेकिन वे डुप्लिकेट मानों अब Phone.CONTACT_ID शामिल प्रत्येक संपर्क के लिए अद्वितीय है। मैं उस विशेष फ़ील्ड के आधार पर संपर्कों की अपनी सरणी सूची फ़िल्टर करना चाहता हूं।hashmap
यहाँ कोड है:
try {
cursor = getApplicationContext().getContentResolver()
.query(Phone.CONTENT_URI, null, null, null, null);
int Idx = cursor.getColumnIndex(Phone.CONTACT_ID);
int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
int photoIdIdx = cursor.getColumnIndex(Phone.PHOTO_THUMBNAIL_URI);
cursor.moveToFirst();
do {
System.out.println("=====>in while");
HashMap<String, String> hashMap = new HashMap<String, String>();
contactid=cursor.getString(Idx);
name = cursor.getString(nameIdx);
phoneNumber = cursor.getString(phoneNumberIdx);
image = cursor.getString(photoIdIdx);
System.out.println("Id--->"+contactid+"Name--->"+name);
if (!phoneNumber.contains("*")) {
hashMap.put("contactid", "" + contactid);
hashMap.put("name", "" + name);
hashMap.put("phoneNumber", "" + phoneNumber);
hashMap.put("image", "" + image);
// hashMap.put("email", ""+email);
hashMapsArrayList.add(hashMap);
}
} while (cursor.moveToNext());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
यहाँ आप देख सकते हैं कि मैं कर्सर से 4 क्षेत्रों प्राप्त करने में कठिनाई रहा हूँ और उन्हें ArrayList hashMapsArrayList
जो ArrayList<HashMap<String, String>> hashMapsArrayList=new ArrayList<HashMap<String,String>>();
अब इस ArrayList डुप्लिकेट फ़ील्ड हैं है में बंधन और मैं चाहता हूँ इसे पर आधारित पर फ़िल्टर करें।
यहाँ कोड है:
System.out.println("Original--->"+hashMapsArrayList);
for(int i=0;i<hashMapsArrayList.size();i++)
{
HashMap<String, String> resultp = new HashMap<String, String>();
resultp = hashMapsArrayList.get(i);
String contactiddup=resultp.get("contactid");
if(!(hashMapsArrayListRemovedup.contains(contactiddup)))
{
System.out.println(hashMapsArrayListRemovedup);
System.out.println("In if added");
hashMapsArrayListRemovedup.add(resultp);
}else{
System.out.println("In else");
}
}
लेकिन इसके बाद के संस्करण कोड काम नहीं कर रहा है और नई ArrayList भी डुप्लिकेट मान हैं।
कृपया मदद करें।
एक नमूना उत्पादन duplicacy:
12-15 14:10:57.217: I/System.out(8971): [{name=Didi America, image=null, phoneNumber=, contactid=7996}, {name=Didi America, image=null, phoneNumber=, contactid=7996}]
क्रम में LinkedHashSet को ArrayList तत्वों जोड़े है – Sree
http://stackoverflow.com/questions/203984/how-do-i-remove-repeated-elements-from-arraylist – Sunny
आपके डुप्लिकेट मान का क्या अर्थ है? प्रदाता – pskink