title: how to implement Custom Auto suggestion in java like google
body: <p>how to implement Java Based Auto suggestion. suppose I have different types of data like firstName, rollNumber, address.</p>
  
  <p>My first requirement is like if user enter first character on text box, then result should be sorted on natural order based on firstName and 10 results should be display.</p>
  
  <p>after space if use enter second character and if it is numbere then RollNumber else lastName should be sorted on natural order as ascending.</p>
  
  <p>or if user type third character then Address should be display on ascending order. there should be no database, you don't have to implement <strong>Solr</strong> or other api. how to implement on pure Java.</p>
  
  <p>here I did not implement the text-box,but I Just took an example to demonstrate</p>
  
  <pre><code>    import java.util.*;
      import java.lang.*;
      import java.io.*;
  
      // A class to represent a student.
      class Student {
          int rollno;
          String name;
          String address;
  
          // Constructor
          public Student(int rollno, String name, String address) {
              this.rollno = rollno;
              this.name = name;
              this.address = address;
          }
  
          // Used to print student details in main()
          public String toString(){
              return this.rollno + " " + this.name +
                                 " " + this.address;
          }
      }
  
      class Sortbyroll implements Comparator&lt;Student&gt; {
          // Used for sorting in ascending order of rollno
          public int compare(Student a, Student b) {
              return a.rollno - b.rollno;
          }
      }
  
      class Sortbyname implements Comparator&lt;Student&gt; {
          // Used for sorting in ascending order of name
          public int compare(Student a, Student b) {
              return a.name.compareTo(b.name);
          }
      }
  
      // Driver class
      class Main {
          public static void main (String[] args) {
              ArrayList&lt;Student&gt; ar = new ArrayList&lt;Student&gt;();
             //here I have thousand student are inserted into 
             //simple collection.
  
              ar.add(new Student(111, "bbbb", "london"));
              ar.add(new Student(131, "aaaa", "nyc"));
              ar.add(new Student(121, "cccc", "jaipur"));
  
              System.out.println("Unsorted");
              for (int i=0; i&lt;ar.size(); i++) {
                  System.out.println(ar.get(i));
              }
  
              //collection sorted by rollno    
              Collections.sort(ar, new Sortbyroll());
  
              System.out.println("\nSorted by rollno");
              for (int i=0; i&lt;ar.size(); i++) {
                  System.out.println(ar.get(i));
              }
  
              //sort by Name
              Collections.sort(ar, new Sortbyname());
  
              System.out.println("\nSorted by name");
              for (int i=0; i&lt;ar.size(); i++) {
                  System.out.println(ar.get(i));
              }
          }
      }
  </code></pre>