List of usage examples for java.lang StringBuilder reverse
@Override
public StringBuilder reverse()
From source file:Main.java
public static void main(String[] argv){ StringBuilder v = new StringBuilder("ABCD"); v.reverse(); System.out.println(v); /*from w w w . ja v a 2 s. co m*/ }
From source file:Main.java
public static void main(String[] argv) { StringBuilder sb = new StringBuilder(); sb.append("java2s.com"); sb.reverse(); System.out.println(sb.toString()); }
From source file:StringBuilderDemo.java
public static void main(String[] args) { String palindrome = "Dot saw I was Tod"; StringBuilder sb = new StringBuilder(palindrome); sb.reverse(); // reverse it System.out.println(sb);/* w ww .j av a 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) { // Create an empty StringBuffer StringBuilder sb = new StringBuilder(); printDetails(sb);//w w w . j av a2 s . c om // Append "good" sb.append("good"); printDetails(sb); // Insert "Hi " in the beginning sb.insert(0, "Hi "); printDetails(sb); // Delete the first o sb.deleteCharAt(1); printDetails(sb); // Append " be with you" sb.append(" be with you"); printDetails(sb); // Set the length to 3 sb.setLength(3); printDetails(sb); // Reverse the content sb.reverse(); printDetails(sb); }
From source file:Palindrome.java
protected static String reverse(String string) { StringBuilder sb = new StringBuilder(string); return sb.reverse().toString(); }
From source file:Main.java
private static String mixStep(String str) { if (str == null || str.isEmpty()) { return ""; }//www .j a v a 2 s .co m if (str.length() == 1) { return str; } if (str.length() == 2) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } StringBuilder sb = new StringBuilder(); String char1 = String.valueOf(str.charAt(0)); String char2 = String.valueOf(str.charAt(1)); String char3 = String.valueOf(str.charAt(2)); if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) < 0)) { return sb.append(mixStep(str.substring(2))).append(str.charAt(1)).append(str.charAt(0)).toString(); } else if ((char1.compareTo(char2) > 0) && (char1.compareTo(char3) > 0)) { String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString(); return sb.append(str.charAt(1)).append(mixReverse).append(str.charAt(0)).toString(); } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) > 0)) { return sb.append(str.charAt(0)).append(mixStep(str.substring(2))).append(str.charAt(1)).toString(); } else if ((char1.compareTo(char2) < 0) && (char1.compareTo(char3) < 0)) { String mixReverse = (new StringBuilder(mixStep(str.substring(2)))).reverse().toString(); return sb.append(str.charAt(0)).append(mixReverse).append(str.charAt(1)).toString(); } return sb.append(str.charAt(1)).append(str.charAt(0)).append(mixStep(str.substring(2))).toString(); }
From source file:Main.java
private static final String ten2Any(long num, int base) { StringBuilder sb = new StringBuilder(7); while (num != 0) { sb.append(str62.charAt((int) (num % base))); num /= base;//from ww w. j a v a 2 s . co m } return sb.reverse().toString(); }
From source file:Main.java
/** * Convert element ID to string, in the radix of 64. The string may contains * the characters: {@code 0-9, a-z, A-Z, _, =}. The generated string can be * parsed by {@code MUtility.parseID()}. * @param id element ID// w w w. j ava 2s. c o m * @return string */ public static String stringID(long id) { StringBuilder builder = new StringBuilder(); int ch = 0; long _id = id; while (_id != 0) { ch = (int) (_id & 0x000000000000003FL); _id >>>= 6; builder.append(alphabet[ch]); } return builder.reverse().toString(); }
From source file:org.apache.hadoop.hbase.mapreduce.TestTableMapReduceBase.java
/** * Implements mapper logic for use across APIs. *///from w w w.j ava 2 s . co m protected static Put map(ImmutableBytesWritable key, Result value) throws IOException { if (value.size() != 1) { throw new IOException("There should only be one input column"); } Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> cf = value.getMap(); if (!cf.containsKey(INPUT_FAMILY)) { throw new IOException("Wrong input columns. Missing: '" + Bytes.toString(INPUT_FAMILY) + "'."); } // Get the original value and reverse it String originalValue = Bytes.toString(value.getValue(INPUT_FAMILY, null)); StringBuilder newValue = new StringBuilder(originalValue); newValue.reverse(); // Now set the value to be collected Put outval = new Put(key.get()); outval.add(OUTPUT_FAMILY, null, Bytes.toBytes(newValue.toString())); return outval; }
From source file:com.silverpeas.ical.StringUtils.java
public static String decodePassword(String encodedPassword) throws Exception { StringBuilder buffer = new StringBuilder(encodedPassword.substring(3)); return decodeBASE64(buffer.reverse().toString().replace('$', '=')).trim(); }