my code is this :
plase help me to deal with the problem when a string is substring of another
String[] arr= {“fafsd”,“fsfs”,“sdgsdg”,“dgsdg”,“dsgsdg”,“fsfsad”};
for(int counter=0;counter<arr.length-1;counter++)
{
int smallest=counter;
for(int i = counter+1;i<=arr.length-1;i++)
{
int index=0;
while(arr[i].charAt(index)==arr[smallest].charAt(index))
{
index++;
}
//
// if(arr[i].length()>arr[smallest].length())
// {
// smallest=i;
// }
if(arr[i].charAt(index)<arr[smallest].charAt(index))
{
smallest=i;
}
}
String temp = arr[smallest];
arr[smallest] = arr[counter];
arr[counter] = temp;
}
System.out.println(Arrays.toString(arr));