-1

I do have a array with million String objects..

ex:String values [] = new String[10000000] 

and I've to reverse all the elements and what is the best way of doing it to improve performance?

6
  • 4
    You can only improve performance if you have something to measure it against. Please post your current code. Commented Sep 23, 2015 at 22:40
  • 3
    It'll be O(n) in any case. Commented Sep 23, 2015 at 22:40
  • 1
    Code a really bad way to do it. Then make it better ... and way you will have improved performance :-) Commented Sep 23, 2015 at 22:44
  • The obvious solution where swap elements starting from the ends and moving to the middle should be optimal, I think. No, I ain't gunna code it for you! Commented Sep 23, 2015 at 22:46
  • 1
    Probable duplicate of stackoverflow.com/q/9995432/869736 Commented Sep 23, 2015 at 23:35

1 Answer 1

1

You are making you task harder than it needs to be by not using the Collections standard library. Instead of an array use a List then use the standard Collections.reverse() method.

List<String> list = Arrays.asList(values);
Collections.reverse(list);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.