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...
  • What outout do you want? Should it say montgomery juneau phoenix etc. ? Would this help: http://stackoverflow.com/questions/2441501/reverse-hello-world-in-java – Darius X. Mar 13 '13 at 01:45

1 Answers1

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());
}
user93353
  • 13,733
  • 8
  • 60
  • 122
  • Wow, that was much more simple than I thought, thanks for the quick response I really appreciate it. – Peter Alpha Mar 13 '13 at 01:51
  • @PeterAlpha - You really ought to do it yourself, "plug and chug". It ain't that hard. – Hot Licks Mar 13 '13 at 01:52
  • @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? – Peter Alpha Mar 13 '13 at 01:57
  • 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())`. – arshajii Mar 13 '13 at 01:58