Inverter uma String

Olá alguem conhece um método ou classe que torne isso possivel!
Por ex… ao digitar 123456 ele escrever 654321 ou entao ao escrever casa e responsa asac??
Seria apenas trocar a posicao na String??

Acho q naum tem nenhum metodo na classe string para fazer isso, mas da pra fazer isso facil:


public class Teste {

  public Teste() {
  }

  static public void main(String args[]) {
    String str = "casa"; 
    char buf[] = new char[4]; 
    int j = str.length() - 1; 

    for (int i=0; i < str.length(); i++) { 
      buf[i] = str.charAt(j); 
      j--; 
    } 

    String strInvertida = String.copyValueOf(buf); 
    System.out.println(strInvertida);
  }

}

Provavelmente deve haver maneira melhor de se fazer isso, mas fiz meio q no vurto aqui

Isso mesmo!
Deu certo
Valeu ai!

Realmente:

String invertida = new StringBuffer("abcde").reverse().toString();

ehehehe

Putz agora sim fecho…
ahuah valeu ai kra!

[quote=“viecili”]

Realmente:

String invertida = new StringBuffer("abcde").reverse().toString();

ehehehe[/quote]

Hauhauh to me sentindo um idiota hauahuah :humm:

Caramba, eu sempre esqueco da classe stringbuffer, fazer o q neh?! Vivendo e aprendendo…
Valeu pela solucao Viecili!