Java: Strings in Java

By Xah Lee. Date: . Last updated: .

Java provides two data types for strings. “String” and “StringBuffer”. Use the “StringBuffer” if you need your string to be modifiable. Variables declared as “String” type cannot be changed. (there's also “StringBuilder”, but you don't have to worry about it now.)

public class S1 {
     public static void main(String[] args) {
         String s1 = "some str";
         StringBuffer s2 = new StringBuffer(9);
         s2.replace(0,0,s1);
         System.out.println(s2.toString());
     }
}

The replace() is a method of “StringBuffer” classs. It replaces parts (or all) of the “StringBuffer” object by a “String” object.

Java

  1. Install
  2. javac java jar javadoc

Java Basics

  1. Print String
  2. Strings
  3. Power Function
  4. Java Types and Type Conversion
  5. Function
  6. Arrays

Class, Inheritance

  1. extends
  2. Constructor
  3. Constructor Return Type
  4. Extending a Class that has Explicit Constructors
  5. static
  6. this
  7. super
  8. Access Specifiers

Abstract class, Interface

  1. abstract
  2. Interface

Package

  1. Package

Misc

  1. Collection, Map
  2. Read/Write File
  3. Convert File Encoding
  4. Complex Numbers in Java
  5. Unicode
  6. Number Literals