I have customized string array for an example:

String[] myArr = {"Zen", "Maruthi","Swift", "Audi"};

I have a tool which will generate array like

String[] output = getCars();//returns {"Swift", "Audi", "Zen", "Maruthi"}

// it should return same as myArr...means {"Zen", "Maruthi","Swift", "Audi"}

I want to sort output arrays to myArr; i am sorting using for loop with comparison of myArr;

So is there any other method to sort customised array?plz help me

share|improve this question

42% accept rate
feedback

1 Answer

Edit:

No need to sort here. Just add similar string into the list as per element(s) sequence in myArr array.

List<String> items=new ArrayList<String>();
for(String item:myArr)
 {
  for(String outputItem:output)
   {
     if(item.equals(outputItem))
        items.add(outputItem);
     }                    
   } 
 for(String s:items)
     System.out.println(s);
share|improve this answer
This will return ascending order...I know this method...But i am asking ,the order should be same myArr(custom)...how to get output same as myArr? – shree May 22 at 4:30
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.