Java - Strings

Strings are a sequence of characters.In the Java programming language, strings are objects.The Java platform provides the String class to create and manipulate strings.

Creating Strings:

The most direct way to create a string is to write:
String greeting = "Hello world!";
You can create String objects by using the new keyword and a constructor.
String helloString = new String("Hello world!");

String Length:

You can use with strings is the length() method, which returns the number of characters contained in the string object.
Below given program is an example of length() , method String class.

Example :

public class StringDemo {

   public static void main(String args[]) {
      String str = "Hello world";
      int len = str.length();
      System.out.println( "String Length is : " + len );



String Length is : 11

Concatenating Strings:

The String class includes a method for concatenating two strings:
Strings are more commonly concatenated with the + operator, as in:
"Hello," + " world" + "!"

Creating Format Strings:

The String class has format() to print output with formatted numbers.
String fs;
fs = String.format("The value of the float variable is " +
                   "%f, while the value of the integer " +
                   "variable is %d, and the string " +
                   "is %s", floatVar, intVar, stringVar);
	 | Raju