2

I am wonding if it is possible to reverse my output so that the strings are written in the reverse order (correctly)?

So I am using the following code to split a string:

String[] capitalArray = revCapitalList.split("\\^");
    for (String u: capitalArray) {
        System.out.println(u);
    }

This is the string I am splitting:

String revCapitalList = "yremogtnom^uaenuj^xineohp^kcor elttil^otnemarcas^revned^droftrah^revod^eessahallat^"
            + "atnalta^ululonoh^esiob^dleifgnirps^silopanaidni^seniom sed^akepot^trofknarf^eguor notab^"
            + "atsugua^silopanna^notsob^gnisnal^luap .ts^noskcaj^ytic nosreffej^aneleh^nlocnil^ytic nosrac^"
            + "drocnoc^notnert^ef atnas^ynabla^hgielar^kcramsib^submuloc^ytic amohalko^melas^grubsirrah^"
            + "ecnedivorp^aibmuloc^erreip^ellivhsan^nitsua^ytic ekal tlas^reileptnom^dnomhcir^aipmylo^notselrahc^nosidam^enneyehc";

The output:

  • yremogtnom
  • uaenuj
  • xineohp
  • etc...
1

1 Answer 1

1

Do you want to reverse the output or reverse the string itself?

If it's just the output, then

for (String u: capitalArray) 
{
    System.out.println(new StringBuffer(u).reverse().toString());
}
Sign up to request clarification or add additional context in comments.

4 Comments

Wow, that was much more simple than I thought, thanks for the quick response I really appreciate it.
@PeterAlpha - You really ought to do it yourself, "plug and chug". It ain't that hard.
@Hot Licks - I appreciate the confidence, but I have been scouring the site for the past few hours to no avail. I think I'm at too low of a level to be welcome here lol. Do they promote smart ass responses here?
It would be better to use StringBuilder here, and note that you don't need the toString call if you're only printing. i.e. System.out.println(new StringBuilder(u).reverse()).

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.