2

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

所以我使用下面的代码来分割一个字符串:

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
  • 瓦埃努伊
  • 新能源
  • ETC...
4

1 回答 1

1

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

如果只是输出,那么

for (String u: capitalArray) 
{
    System.out.println(new StringBuffer(u).reverse().toString());
}
于 2013-03-13T01:47:08.563 回答