Peter Alpha
Peter Alpha

Reputation: 25

Format string array to reverse strings

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:

Upvotes: 2

Views: 683

Answers (1)

user93353
user93353

Reputation: 14039

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());
}

Upvotes: 1

Related Questions