title: Get index first and last same item in ArrayList?
body: <p>I have a model :</p>
  
  <pre><code>public class Unprocessed_DistanceTime_D {
      private String lat;
      private String lng;
      private String date;
      private String time;
      private String counts;
      private String userCode;
  
      public String getLat() {
          return lat;
      }
  
      public void setLat(String lat) {
          this.lat = lat;
      }
  
      public String getLng() {
          return lng;
      }
  
      public void setLng(String lng) {
          this.lng = lng;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public String getTime() {
          return time;
      }
  
      public void setTime(String time) {
          this.time = time;
      }
  
      public String getCounts() {
          return counts;
      }
  
      public void setCounts(String counts) {
          this.counts = counts;
      }
  
      public String getUserCode() {
          return userCode;
      }
  
      public void setUserCode(String userCode) {
          this.userCode = userCode;
      }
  }
  </code></pre>
  
  <p>And I fill my model with bellow data :</p>
  
  <pre><code>     DATE      TIME       LAT            LNG         COUNT 
  1395/04/26    12:13:44    34.6117392    50.8548033    7
  1395/04/26    12:13:49    34.6117392    50.8548033    7
  1395/04/26    12:13:58    34.6117392    50.8548033    7
  1395/04/26    12:14:00    34.6117392    50.8548033    7
  1395/04/26    12:14:22    34.6117392    50.8548033    7
  1395/04/26    12:14:44    34.6117392    50.8548033    7
  1395/04/26    12:14:49    34.6117392    50.8548033    7
  1395/04/26    12:14:58    34.6113533    50.8551068    27
  1395/04/26    12:14:58    34.6113533    50.8551068    27
  1395/04/26    12:15:00    34.6113533    50.8551068    27
  1395/04/26    12:15:22    34.6113533    50.8551068    27
  1395/04/26    12:15:35    34.6322184    50.8596414    9
  1395/04/26    12:15:44    34.6113533    50.8551068    27
  1395/04/26    12:15:49    34.6113533    50.8551068    27
  1395/04/26    12:15:58    34.6113533    50.8551068    27
  1395/04/26    12:15:58    34.6113533    50.8551068    27
  1395/04/26    12:16:00    34.6113533    50.8551068    27
  1395/04/26    12:16:09    34.6322184    50.8596414    9
  1395/04/26    12:16:22    34.6113533    50.8551068    27
  1395/04/26    12:16:44    34.6113533    50.8551068    27
  1395/04/26    12:16:49    34.6113533    50.8551068    27
  1395/04/26    12:16:58    34.6113533    50.8551068    27
  1395/04/26    12:16:58    34.6113533    50.8551068    27
  1395/04/26    12:17:00    34.6113533    50.8551068    27
  1395/04/26    12:17:22    34.6113533    50.8551068    27
  1395/04/26    12:17:44    34.6113533    50.8551068    27
  1395/04/26    12:17:49    34.6113533    50.8551068    27
  1395/04/26    12:17:58    34.6113533    50.8551068    27
  1395/04/26    12:17:58    34.6113533    50.8551068    27
  1395/04/26    12:18:00    34.6113533    50.8551068    27
  1395/04/26    12:18:22    34.6113533    50.8551068    27
  1395/04/26    12:18:38    34.6322184    50.8596414    9
  1395/04/26    12:18:44    34.6113533    50.8551068    27
  1395/04/26    12:18:49    34.6113533    50.8551068    27
  1395/04/26    12:18:51    34.6322184    50.8596414    9
  1395/04/26    12:18:58    34.6113533    50.8551068    27
  1395/04/26    12:18:58    34.6113533    50.8551068    27
  1395/04/26    12:19:00    34.6113533    50.8551068    27
  1395/04/26    12:19:01    34.6113415    50.8562128    22
  1395/04/26    12:19:22    34.6113415    50.8562128    22
  1395/04/26    12:19:44    34.6113415    50.8562128    22
  1395/04/26    12:19:49    34.6113415    50.8562128    22
  1395/04/26    12:19:58    34.6113415    50.8562128    22
  1395/04/26    12:19:58    34.6113415    50.8562128    22
  1395/04/26    12:20:00    34.6113415    50.8562128    22
  1395/04/26    12:20:01    34.6113415    50.8562128    22
  1395/04/26    12:21:41    34.6322184    50.8596414    9
  1395/04/26    12:22:32    34.6113415    50.8562128    22
  1395/04/26    12:22:36    34.6322184    50.8596414    9
  1395/04/26    12:25:00    34.6113415    50.8562128    22
  1395/04/26    12:25:04    34.6113415    50.8562128    22
  1395/04/26    12:25:13    34.6113415    50.8562128    22
  1395/04/26    12:25:13    34.6113415    50.8562128    22
  1395/04/26    12:25:16    34.6113415    50.8562128    22
  1395/04/26    12:25:16    34.6113415    50.8562128    22
  1395/04/26    12:25:37    34.6113415    50.8562128    22
  1395/04/26    12:25:37    34.6322184    50.8596414    9
  1395/04/26    12:26:00    34.6113415    50.8562128    22
  1395/04/26    12:26:04    34.6113415    50.8562128    22
  1395/04/26    12:26:13    34.6113415    50.8562128    22
  1395/04/26    12:26:20    34.6113415    50.8562128    22
  1395/04/26    12:26:38    34.6113415    50.8562128    22
  1395/04/26    12:26:38    34.6322184    50.8596414    9
  1395/04/26    12:26:39    34.6113415    50.8562128    22
  1395/04/26    12:29:46    34.6322184    50.8596414    9
  </code></pre>
  
  <p>And I write bellow code but don't work for me for get the index of first and last items that are same , I use from you code but I can't get true answer .
  My data is sort base time and I don't like change it I should work on this data without change .</p>
  
  <p>My code is here :</p>
  
  <pre><code>public class ComputeDetailMoreActivity_E extends AppCompatActivity {
      Context context;
  
      @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_computedetailmore);
              int count = 1;
              int X = 2;
              boolean flag = true;
              int index1 = -1;
              int index2 = -1;
              Integer counter = 0;
              for (int i = 0; i &lt; listCDM.size() - 1; i++) {
                  if (listCDM.get(i).getDate().equalsIgnoreCase(listCDM.get(count).getDate()) &amp;&amp;
                          listCDM.get(i).getLat().equalsIgnoreCase(listCDM.get(count).getLat()) &amp;&amp;
                          listCDM.get(i).getLng().equalsIgnoreCase(listCDM.get(count).getLng()) &amp;&amp;
                          listCDM.get(i).getCounts().equalsIgnoreCase(listCDM.get(count).getCounts())) {
                      if (flag) {
                          index1 = i;
                          flag = false;
                          counter++;
                      }
                  } else {
                      if (X &lt; listCDM.size()) {
                          if (!listCDM.get(count).getLat().equalsIgnoreCase(listCDM.get(X).getLat()) &amp;&amp;
                                  !listCDM.get(count).getLng().equalsIgnoreCase(listCDM.get(X).getLng()) &amp;&amp;
                                  !listCDM.get(count).getCounts().equalsIgnoreCase(listCDM.get(X).getCounts())||
                                  !listCDM.get(count).getDate().equalsIgnoreCase(listCDM.get(X).getDate())) {
  
                              Log.i("ADFASFEWRWE", "C : " + listCDM.get(X).getCounts() + "**" +
                                      listCDM.get(X).getTime());
                              index2 = i;
                              Log.i("ASDASRDWE",i + "");
                              int error = count;
                              counter = 2;
                          }
                          if (listCDM.get(count).getLat().equalsIgnoreCase(listCDM.get(X).getLat()) &amp;&amp;
                                  listCDM.get(count).getLng().equalsIgnoreCase(listCDM.get(X).getLng()) &amp;&amp;
                                  listCDM.get(count).getCounts().equalsIgnoreCase(listCDM.get(X).getCounts()) &amp;&amp;
                                  listCDM.get(count).getDate().equalsIgnoreCase(listCDM.get(X).getDate())) {
  
                              index2 = i;
                              flag = true;
                              counter++;
                          }
                          Log.i("RRTTGGTT", counter + "");
                          if (counter == 2) {
                              Log.i("ASDWERWEDAVVGG", index1 + " : " + index2);
                              flag = true;
                              counter = 0;
                              index1 = -1;
                              index2 = -1;
                          }
                      }
               }
               count++;
                X++;
  
               }
  
        }
  }
  </code></pre>
  
  <p>My out put is :</p>
  
  <pre><code>7 : 6
  7 : 10
  12 : 16
  18 : 30
  32 : 33
  38 : 45
  -1 : 46
  -1 : 47
  49 : 55
  57 : 61
  -1 : 62
  </code></pre>