Java source code examples

Java source code samples. Java code examples.

Entries Tagged as 'java.lang'

Replaces a substring with specified String from a StringBuffer

April 20th, 2008 · No Comments

Replaces a substring with specified String from a StringBuffer

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.replace(0, 5, “Hai”);
System.out.println(buff);
}
}

[Read more →]

Tags: java.lang

Deletes a character at the specified index from a StringBuffer

April 20th, 2008 · No Comments

Deletes a character at the specified index from a StringBuffer

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.deleteCharAt(0);

System.out.println(buff);
}
}

[Read more →]

Tags: java.lang

Deletes a substring from a StringBuffer

April 20th, 2008 · No Comments

Deletes a substring from a StringBuffer

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.delete(0, 5);

System.out.println(buff);
}
}

[Read more →]

Tags: java.lang

Appends a String to the ends of a StringBuffer

April 20th, 2008 · No Comments

Appends a String to the ends of a StringBuffer

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello”);
buff.append(”World”);

System.out.println(buff);
}
}

[Read more →]

Tags: java.lang

Replaces a character of a StringBuffer

April 20th, 2008 · No Comments

Replaces a character of a StringBuffer

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.setCharAt(1, ‘E’);

System.out.println(buff);
}
}

[Read more →]

Tags: java.lang

Copy the characters of a StringBuffer to a characters array

April 20th, 2008 · No Comments

Copy the characters of a StringBuffer to a characters array

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);

char value[] = new char[5];
buff.getChars(0, 5, value, 0);

System.out.println(new String(value));
}
}

[Read more →]

Tags: java.lang

Finds the character at a given position of a StringBuffer.

April 20th, 2008 · No Comments

Finds the character at a given position of a StringBuffer.

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);

char value = buff.charAt(4);

System.out.println(value);
}
}

[Read more →]

Tags: java.lang

Sets the length of a StringBuffer

April 20th, 2008 · No Comments

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.setLength(15);

int value = buff.length();

System.out.println(value);
}
}

[Read more →]

Tags: java.lang

Sets the length of a StringBuffer

April 20th, 2008 · No Comments

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(”Hello World”);
buff.setLength(15);

int value = buff.length();

System.out.println(value);
}
}

[Read more →]

Tags: java.lang

Trims the StringBuffer capacity to its size.

April 20th, 2008 · No Comments

public class StringBufferExample {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer(100);
buff.append(”Hello World”);
buff.trimToSize();
int value = buff.capacity();

System.out.println(value);
}
}

[Read more →]

Tags: java.lang