title: How to get Distinct list of Call log with descending order of date in android using Treeset
body: <p>In my application, i just want call log with distinct and sorted with descending of date.  I tried below code and not getting exact result</p>
  
  <p>my code as follows</p>
  
  <pre><code>    public class MainActivity extends Activity {
      //  List&lt;CLogItem&gt; clogitems = new ArrayList&lt;CLogItem&gt;();
          Set clogitems = new TreeSet();
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
          }
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
          }
  
          public void onClick(View v){
              getCallDetails(this);
  
              TextView tv1 = (TextView)findViewById(R.id.tv1);
              String str = "";
  
              Iterator sitr=clogitems.iterator();
              while(sitr.hasNext())
              {
                  CLogItem clitem=(CLogItem) sitr.next();
                  str = str + "P: " + clitem.No + "\n";
                  str = str + "N: " + clitem.Name + "\n";
                  str = str + "--------------------------------------------\n";
              }
              tv1.setText(str);
          }
  
          private void getCallDetails(Context context) {
              StringBuffer stringBuffer = new StringBuffer();
              Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI,
                      null, null, null, CallLog.Calls.DATE + " DESC");
              int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
              int date = cursor.getColumnIndex(CallLog.Calls.DATE);
              int iname = cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
              while (cursor.moveToNext()) {
                  CLogItem clitem = new CLogItem();
                  clitem.No = cursor.getString(number);
                  clitem.Name = cursor.getString(iname);
                  clitem.lDate = Long.valueOf(cursor.getString(date));
                  clogitems.add(clitem);
              }
              cursor.close();
          }
  
          public static class CLogItem implements Comparable {
              String No;
              String Name;
              long lDate;
  
              public CLogItem(){
                  this.No = "";
                  this.Name = "";
                  this.lDate = 0;
              }
  
              @Override
              public int compareTo(Object arg0) {
                  CLogItem l = (CLogItem)arg0;
  
                   int fnResult = this.No.compareTo(l.No);
                   if( fnResult == 0 ){
                          if (lDate &gt; l.lDate) {
                              return -1;
                          }
                          else if (lDate &lt;  l.lDate) {
                              return 1;
                          }
                          else {
                              return 0;
                          }
  
                   }
                   return fnResult;
              }
          }
  
  
      }
  </code></pre>
  
  <p>please help me to sort out this issue </p>
  
  <p>thanks in advance</p>