title: Display nth highest value if matched with comboBox value
body: <p>I am using cosine similarity function to compare the value between user input and the data in SQL. The highest value will be retrieved and displayed.</p>
  
  <p>However, <code>k</code> is the value getting from <code>comboBox</code> and it is hard constraints which mean they need to be fulfilled. So I have set it to something like: </p>
  
  <p>The highest value found in index X . Before display, it will check whether day is equal to k. If not, it will look at the second highest and so on until day is equal to k. </p>
  
  <p>But this doesn't make sense at all. If day is equal to k only when it is in the ninth highest value, then I need to set until ninth highest value?  Is there any method can solve this?</p>
  
  <pre><code>private void pick_highest_value_here_and_display(ArrayList&lt;Double&gt; value,
      int k) throws Exception {
    // TODO Auto-generated method stub
    double aa[] = value.stream().mapToDouble(v -&gt; v.doubleValue()).toArray();
    double highest = Double.MIN_VALUE;
    double secHighest = Double.MIN_VALUE;
    int highestIndex = 0;
  
    for (int i = 0; i &lt; aa.length; i++) {
      if (aa[i] &gt; highest) {
        highest = aa[i];
        highestIndex = i;
      }
    }
    System.out.println("The highest value is " + highest + "");
    System.out.println("It is found at index " + highestIndex + "");
    String sql = "Select Day from menu where ID =?";
    DatabaseConnection db = new DatabaseConnection();
    Connection conn = db.getConnection();
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1, highestIndex);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
      int aaa = rs.getInt("Day");
      System.out.println(aaa);
      if (aaa == k) // check whether aaa(day) is equal to k (comboBox)
      {
        String sql1 = "Select * from placeseen where ID =?";
        DatabaseConnection db1 = new DatabaseConnection();
        Connection conn1 = db1.getConnection();
        PreparedStatement ps1 = conn1.prepareStatement(sql1);
        ps1.setInt(1, highestIndex);
        ResultSet rs1 = ps1.executeQuery();
        if (rs1.next()) {
          String a = rs1.getString("place1");
          String bbb = rs1.getString("place2");
          Tourism to = new Tourism();
          to.setPlace1(a);
          to.setPlace2(bbb);
          DispDay dc = new DispDay();
          dc.setVisible(true);
        }
        ps1.close();
        rs1.close();
        conn1.close();
      } else // if not equal
      {
  
        int secIndex = 0;
        for (int i = 0; i &lt; aa.length; i++) {
          if (aa[i] &gt; secHighest) {
            secHighest = aa[i];
            secIndex = i;
          }
        }
        System.out.println("The second highest value is " + secHighest + "");
        System.out.println("It is found at index " + secIndex + "");
        String sql2 = "Select Day from menu where ID =?";
        DatabaseConnection db2 = new DatabaseConnection();
        Connection conn2 = db2.getConnection();
        PreparedStatement ps2 = conn.prepareStatement(sql2);
        ps2.setInt(1, secIndex);
        ResultSet rs2 = ps.executeQuery();
        if (rs2.next()) {
          int de = rs2.getInt("Day");
          System.out.println(de);
          if (de == k) {
            String l = "Select * from placeseen where ID =?";
            DatabaseConnection db3 = new DatabaseConnection();
            Connection conn3 = db3.getConnection();
            PreparedStatement ps3 = conn3.prepareStatement(l);
            ps3.setInt(1, secIndex);
            ResultSet rs3 = ps3.executeQuery();
            if (rs3.next()) {
              String a = rs3.getString("place1");
              String bbb = rs3.getString("place2");
              Tourism to = new Tourism();
              to.setPlace1(a);
              to.setPlace2(bbb);
              DispDay dc = new DispDay();
              dc.setVisible(true);
            }
            ps3.close();
            rs3.close();
            conn3.close();
          }
        }
      }
      ps.close();
      rs.close();
      conn.close();
    }
  }
  </code></pre>