title: Autocomplete console text
body: <p>I need to create a Java console application that make suggestions for the name of food to the user. This information will be fetched from <code>sqlite</code> database file. User will write text and program will whispering the names of items. When user want to complete the text he press the TAB key and application will get next item. 
  I have already all databases items recorded at ArrayList.</p>
  
  <p><a href="https://i.stack.imgur.com/TzEaA.gif" rel="nofollow noreferrer">My main idea(without everything except for the top text)</a></p>
  
  <p>Part of code -
  Main class</p>
  
  <pre><code>    Scanner sc=new Scanner(System.in);
      ArrayList&lt;Food&gt; foodList= DatabaseServices.loadAllFood();
      ArrayList&lt;String&gt; foodNameList=new ArrayList();
      String nameFood;
  
      while (condition) {//when I have all recipe names
        //some code
        nameFood=sc.nextLine();
        foodNameList(nameFood);
      }
  </code></pre>
  
  <p><em>Edit:</em></p>
  
  <p>DatabaseServices class</p>
  
  <pre><code>public ArrayList&lt;food&gt; loadAllFood() {//fetch data and sort them
          ArrayList&lt;food&gt; foodList = new ArrayList&lt;&gt;();
          try {
              String SQL = "SELECT * FROM foods ";
              ResultSet data = MyDatabaseConnection.executeQuery(SQL);
  
  
              do {
                  Food food= new Food(data.getInt("food_id"),
                          data.getString("nfood_nazev"),
                          data.getInt("food_bilkoviny"),
                          data.getInt("food_sacharidy"),
                          data.getInt("food_tuky"));
                  foodList .add(potravina);
              } while (data.next());
  
              Collections.sort(foodList );
  
          } catch (SQLException ex) {
              Logger.getLogger(DatabaseServices.class.getName()).log(Level.SEVERE, null, ex);
          }
      return foodList;
      }
  </code></pre>
  
  <p>Is there some easy way to do that???</p>