Question: I want to sort string array based on on input string , for example thin we have these text

```
"united state"
"sample united"
"united kingdom"
"greece"
"uzbakestan"

```

so when user entered `united` , output will be :

```
"united state"
"united kingdom"
"sample united"
"greece"
"uzbakestan"

```

it shows `united` at first and sort them.

Answer: 
if you use ArrayList you have to use **Collection** to the sort the array list.

For example:

```
Collections.sort(arrayList);

```

To view:

```
    Iterator<String> i = a.iterator();
    while(i.hasNext()) {
        System.out.println(i.next());
    }

```
I think, first you are listing all the items which contains input keyword. Then adding other items to the list.

```
for(int i=0;i<mylist.size();i++) {
   //splitting item by space to match with the inputText
   String[] myString = mylist.get(i);
   for(int j=0;j<myString.length;j++) {
      if(myString[j].equals(inputText)) {
        myNewList.add(mylist.get(i));
        break;
      }

    }

```

}

```
for(int i=0;i<mylist.size();i++) {
   if(!mynewList.contains(mylist.get(i))) {
     myNewList.add(mylist.get(i));
   }

 }

```

might be there is some easy way to do this. But i hope this will give you the output what u r looking for.

First it will add all the strings which contains the input text to the new list, then adding remaining strings.