Example usage for java.lang StringBuffer reverse

List of usage examples for java.lang StringBuffer reverse

Introduction

In this page you can find the example usage for java.lang StringBuffer reverse.

Prototype

@Override
public synchronized StringBuffer reverse() 

Source Link

Usage

From source file:ReverseConsoleInput.java

public static void main(String args[]) throws Exception {
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    // Read and process lines from console
    String s;//from   ww  w . j  ava  2s  . com
    while ((s = br.readLine()) != null) {
        StringBuffer sb = new StringBuffer(s);
        sb.reverse();
        System.out.println(sb);
    }
    isr.close();
}

From source file:MainClass.java

public static void main(String[] arg) {
    StringBuffer palindrome = new StringBuffer("so many dynamos");

    palindrome.reverse();

    System.out.println(palindrome);

}

From source file:Main.java

public static void main(String[] argv) {
    StringBuffer sb = new StringBuffer();
    sb.append("java2s.com");

    sb.reverse();
    System.out.println(sb.toString());
}

From source file:Main.java

public static void main(String[] args) {
    StringBuffer sb = new StringBuffer("this is a test");
    System.out.println(sb);//  ww w . ja va  2  s .c o  m
    sb.reverse();
    System.out.println(sb);

}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb1 = new StringBuffer("abcde");
    sb1.append("abcdefghij");
    StringBuffer sb2 = sb1.reverse();
    System.out.println(sb1);/*from   w w w.  j  ava  2  s  . c o  m*/
    System.out.println(sb2);
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer buffer = new StringBuffer("hello there");

    System.out.printf("buffer = %s\n", buffer.toString());
    System.out.printf("Character at 0: %s\nCharacter at 4: %s\n\n", buffer.charAt(0), buffer.charAt(4));

    char charArray[] = new char[buffer.length()];
    buffer.getChars(0, buffer.length(), charArray, 0);
    System.out.print("The characters are: ");

    for (char character : charArray)
        System.out.print(character);

    buffer.setCharAt(0, 'H');
    buffer.setCharAt(6, 'T');
    System.out.printf("\n\nbuf = %s", buffer.toString());

    buffer.reverse();
    System.out.printf("\n\nbuf = %s\n", buffer.toString());
}

From source file:Main.java

protected static String reverse(String string) {
    StringBuffer sb = new StringBuffer(string);
    return sb.reverse().toString();
}

From source file:Main.java

/**
 * //from ww w.ja v a 2s.  c  o  m
 * @param str
 * @return
 */
public static String strRev(String str) {
    StringBuffer sb = new StringBuffer(str);
    String newstr = sb.reverse().toString();
    return newstr;
}

From source file:Palindrome.java

protected static String reverse(String string) {
    StringBuffer sb = new StringBuffer(string);

    return sb.reverse().toString();
}

From source file:Main.java

public static String spliteMobile(String mobile) {
    StringBuffer buffer = new StringBuffer(mobile);
    char[] chars = buffer.reverse().toString().toCharArray();
    StringBuffer result = new StringBuffer();
    for (int i = chars.length - 1; i >= 0; i--) {
        if (i % 4 == 0) {
            result.append(chars[i]).append(" ");
        } else {//from www.  ja  v a 2 s . c o m
            result.append(chars[i]);
        }
    }
    return result.toString();
}