List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:Main.java
public static void main(String args[]) { StringBuffer buffer = new StringBuffer(); Object objectRef = "java2s.com"; buffer.insert(0, objectRef); System.out.println(buffer.toString()); }
From source file:MainClass.java
public static void main(String[] args) { StringBuffer sb1 = new StringBuffer("xy"); System.out.println(sb1);//from w w w.ja va 2s . c o m sb1.insert(0, false); System.out.println(sb1); StringBuffer sb2 = new StringBuffer("xy"); System.out.println(sb2); sb2.insert(1, true); System.out.println(sb2); }
From source file:Main.java
public static void main(String args[]) { Object objectRef = "hello"; String string = "goodbye"; char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; boolean booleanValue = true; char characterValue = 'K'; int integerValue = 7; long longValue = 10000000; float floatValue = 2.5f; double doubleValue = 33.3; StringBuffer buffer = new StringBuffer(); buffer.insert(0, objectRef); buffer.insert(0, " "); buffer.insert(0, string);// w w w.j a v a2 s .co m buffer.insert(0, " "); buffer.insert(0, charArray); buffer.insert(0, " "); buffer.insert(0, charArray, 3, 3); buffer.insert(0, " "); buffer.insert(0, booleanValue); buffer.insert(0, " "); buffer.insert(0, characterValue); buffer.insert(0, " "); buffer.insert(0, integerValue); buffer.insert(0, " "); buffer.insert(0, longValue); buffer.insert(0, " "); buffer.insert(0, floatValue); buffer.insert(0, " "); buffer.insert(0, doubleValue); System.out.printf("buffer after inserts:\n%s\n\n", buffer.toString()); }
From source file:Main.java
public static void main(String[] arg) { StringBuffer buffer = new StringBuffer("from java2s.com"); CharSequence cs = "java2s.com"; buffer.insert(2, cs); System.out.println(buffer);// w w w . ja v a 2 s.c o m }
From source file:Main.java
public static void main(String args[]) { StringBuffer buffer = new StringBuffer(); char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; buffer.insert(0, charArray); System.out.println(buffer.toString()); }
From source file:MainClass.java
public static void main(String args[]) { Object objectRef = "hello"; String string = "goodbye"; char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; boolean booleanValue = true; char characterValue = 'K'; int integerValue = 7; long longValue = 10000000; float floatValue = 2.5f; double doubleValue = 33.3; StringBuffer buffer = new StringBuffer(); buffer.insert(0, objectRef); buffer.insert(0, " "); buffer.insert(0, string);/*from w ww. ja va 2 s . com*/ buffer.insert(0, " "); buffer.insert(0, charArray); buffer.insert(0, " "); buffer.insert(0, charArray, 3, 3); buffer.insert(0, " "); buffer.insert(0, booleanValue); buffer.insert(0, " "); buffer.insert(0, characterValue); buffer.insert(0, " "); buffer.insert(0, integerValue); buffer.insert(0, " "); buffer.insert(0, longValue); buffer.insert(0, " "); buffer.insert(0, floatValue); buffer.insert(0, " "); buffer.insert(0, doubleValue); System.out.printf("buffer after inserts:\n%s\n\n", buffer.toString()); buffer.deleteCharAt(10); buffer.delete(2, 6); System.out.printf("buffer after deletes:\n%s\n", buffer.toString()); }
From source file:InsertDemo.java
public static void main(String[] args) { StringBuffer palindrome = new StringBuffer("A man, a plan, a canal; Panama."); palindrome.insert(15, "a cat, "); System.out.println(palindrome); }
From source file:Main.java
public static void main(String[] args) { boolean b = true; StringBuffer sb1 = new StringBuffer("1234567890"); sb1.insert(6, b); System.out.println(sb1);/*from ww w. j av a 2s . c om*/ char c = 'Y'; sb1.insert(6, c); System.out.println(sb1); char[] c1 = new char[] { 'Y', 'e', 's' }; sb1.insert(6, c1); System.out.println(sb1); double d = 1.0; sb1.insert(6, d); System.out.println(sb1); float f = 2.0f; sb1.insert(6, f); System.out.println(sb1); int i = 5; sb1.insert(6, i); System.out.println(sb1); long l = 10; sb1.insert(6, l); System.out.println(sb1); Object obj = new String("b"); sb1.insert(6, obj); System.out.println(sb1); String str = "a"; sb1.insert(6, str); System.out.println(sb1); }
From source file:TextVerifyInputFormatDate.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.BORDER); text.setText("YYYY/MM/DD"); ;/*from w w w. j a v a 2 s . c o m*/ final Calendar calendar = Calendar.getInstance(); text.addListener(SWT.Verify, new Listener() { boolean ignore; public void handleEvent(Event e) { if (ignore) return; e.doit = false; StringBuffer buffer = new StringBuffer(e.text); char[] chars = new char[buffer.length()]; buffer.getChars(0, chars.length, chars, 0); if (e.character == '\b') { for (int i = e.start; i < e.end; i++) { switch (i) { case 0: /* [Y]YYY */ case 1: /* Y[Y]YY */ case 2: /* YY[Y]Y */ case 3: /* YYY[Y] */ { buffer.append('Y'); break; } case 5: /* [M]M */ case 6: /* M[M] */ { buffer.append('M'); break; } case 8: /* [D]D */ case 9: /* D[D] */ { buffer.append('D'); break; } case 4: /* YYYY[/]MM */ case 7: /* MM[/]DD */ { buffer.append('/'); break; } default: return; } } text.setSelection(e.start, e.start + buffer.length()); ignore = true; text.insert(buffer.toString()); ignore = false; text.setSelection(e.start, e.start); return; } int start = e.start; if (start > 9) return; int index = 0; for (int i = 0; i < chars.length; i++) { if (start + index == 4 || start + index == 7) { if (chars[i] == '/') { index++; continue; } buffer.insert(index++, '/'); } if (chars[i] < '0' || '9' < chars[i]) return; if (start + index == 5 && '1' < chars[i]) return; /* [M]M */ if (start + index == 8 && '3' < chars[i]) return; /* [D]D */ index++; } String newText = buffer.toString(); int length = newText.length(); StringBuffer date = new StringBuffer(text.getText()); date.replace(e.start, e.start + length, newText); calendar.set(Calendar.YEAR, 1901); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); String yyyy = date.substring(0, 4); if (yyyy.indexOf('Y') == -1) { int year = Integer.parseInt(yyyy); calendar.set(Calendar.YEAR, year); } String mm = date.substring(5, 7); if (mm.indexOf('M') == -1) { int month = Integer.parseInt(mm) - 1; int maxMonth = calendar.getActualMaximum(Calendar.MONTH); if (0 > month || month > maxMonth) return; calendar.set(Calendar.MONTH, month); } String dd = date.substring(8, 10); if (dd.indexOf('D') == -1) { int day = Integer.parseInt(dd); int maxDay = calendar.getActualMaximum(Calendar.DATE); if (1 > day || day > maxDay) return; calendar.set(Calendar.DATE, day); } else { if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY) { char firstChar = date.charAt(8); if (firstChar != 'D' && '2' < firstChar) return; } } text.setSelection(e.start, e.start + length); ignore = true; text.insert(newText); ignore = false; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:Main.java
public static String formathhmmss(String hhmmss) { if (null != hhmmss && hhmmss.length() == 6) { StringBuffer sb = new StringBuffer(hhmmss); sb.insert(2, ":"); sb.insert(5, ":"); return sb.toString(); }/*from w w w.j a v a 2 s.co m*/ return ""; }