格式化字符串数组以反转字符串

时间:2013-03-13 01:40:44

标签: java string arrays

我想知道是否可以反转我的输出以便以相反的顺序(正确)写出字符串?

所以我使用以下代码分割字符串:

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

这是我分裂的字符串:

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";

输出:

  • yremogtnom
  • uaenuj
  • xineohp
  • 等...

1 个答案:

答案 0 :(得分:1)

您想要反转输出还是反转字符串本身?

如果它只是输出,那么

for (String u: capitalArray) 
{
    System.out.println(new StringBuffer(u).reverse().toString());
}