List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:Main.java
public static void main(String args[]) { StringBuilder sb = new StringBuilder("java2s.com."); sb.deleteCharAt(0); System.out.println("After deleteCharAt: " + sb); }
From source file:Main.java
public static void main(String[] args) { StringBuilder lipsum = new StringBuilder("Lorem ipsum dolor sit amet."); System.out.println("lipsum = " + lipsum.toString()); lipsum.delete(0, 28);/*from w w w. ja va 2s . co m*/ System.out.println("lipsum = " + lipsum.toString()); lipsum.deleteCharAt(lipsum.length() - 1); System.out.println("lipsum = " + lipsum.toString()); }
From source file:Main.java
public static void main(String[] args) { // Create an empty StringBuffer StringBuilder sb = new StringBuilder(); printDetails(sb);/*from w w w . ja v 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:com.heliosapm.opentsdb.client.boot.JavaAgentInstaller.java
public static void main(final String[] args) { if (args.length == 0) { loge("Usage: java com.heliosapm.opentsdb.client.boot.JavaAgentInstaller \n\t<PID | Name to match> \n\t[-list | -listjson] \n\t[-p k=v] \n\t[-config URL|File]"); }//from ww w. j av a 2s .co m final long pid; if (isPid(args[0])) { pid = Long.parseLong(args[0].trim()); } else if ("-list".equalsIgnoreCase(args[0])) { printJVMs(myId); return; } else if ("-listjson".equalsIgnoreCase(args[0])) { printJVMsInJSON(myId); return; } else { pid = findPid(args[0]); } if (pid < 1) { System.exit(-1); } log("Installing JavaAgent to PID: %s from JAR: %s", pid, JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation()); VirtualMachine vm = null; try { final String loc = new File( JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation().getFile()) .getAbsolutePath(); vm = VirtualMachine.attach("" + pid); log("Connected to process %s, loading Agent from %s", vm.id(), loc); if (args.length > 1) { StringBuilder b = new StringBuilder(); for (int i = 1; i < args.length; i++) { b.append(args[i]).append("|~"); if ("-config".equalsIgnoreCase(args[i])) { i++; final URL url = URLHelper.toURL(args[i]); b.append(url).append("|~"); } } b.deleteCharAt(b.length() - 1); b.deleteCharAt(b.length() - 1); log("Loading with options [%s]", b); vm.loadAgent(loc, b.toString()); } else { log("Loading with no options"); vm.loadAgent(loc); } log("Agent loaded to process %s", vm.id()); System.exit((int) pid); } catch (Exception ex) { loge("Failed to attach to process %s. Stack trace follows...", pid); ex.printStackTrace(System.err); } finally { if (vm != null) { try { vm.detach(); log("Detached from process %s", pid); } catch (Exception ex) { } } } }
From source file:Main.java
public static String _byteArrayToHex(byte[] a) { StringBuilder sb = new StringBuilder(); for (byte b : a) sb.append(String.format("%02x-", b & 0xff)); sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:Main.java
public static String getUserAgent() { StringBuilder model = new StringBuilder(android.os.Build.MODEL); if (model.toString().startsWith("\"")) { model.deleteCharAt(0); }//from ww w .j ava 2s .c o m if (model.toString().endsWith("\"")) { model.deleteCharAt(model.length() - 1); } return model.toString(); }
From source file:Main.java
public static String showByteArray(byte[] data) { if (null == data) { return null; }//w w w. java2s .com StringBuilder sb = new StringBuilder("{"); for (byte b : data) { sb.append(b).append(","); } sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:Main.java
public static String bytesToAddress(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(String.format("%02X:", b)); }/*w w w.jav a 2s . c o m*/ sb.deleteCharAt(sb.length() - 1); // remove last semicolon return sb.toString(); }
From source file:Main.java
public static String collectionAsString(Collection<?> collection) { if (collection == null) return "[null]"; if (collection.size() == 0) return "[empty]"; StringBuilder builder = new StringBuilder(); for (Object obj : collection) { builder.append(obj).append(", "); }//from ww w . j a v a 2 s. c om builder.deleteCharAt(builder.length() - 1); return builder.toString(); }
From source file:Main.java
public static String stringify(Object[] array) { if (isEmpty(array)) { return ""; } else {/*from www .j av a2s . co m*/ StringBuilder sb = new StringBuilder("{ "); for (Object obj : array) sb.append(obj).append(", "); return sb.deleteCharAt(sb.length() - 2).append("}").toString(); } }