JAVA

Creation, concatenation and conversion of a string, changing case of string, character extraction, String

Creation:

1.using string literal : String literal is created by double quote.

EX.   String s = “Tutorialink”;
      String s1= “Welcome”; // no new object will be created.

2.Using new keyword : JVM will create a new string object in normal heap memory and the literal “welcome” will be placed in the string constant pool.

EX.  String s= new String(“Tutorialink”); // creates new objects

Concatenation: in java string objects are immutable simply means un-modifiable or unchangeable.

Example:

Ex. Public static void main(String args[ ])
  {
    String s=“Indian”;
    s=s.concat(“Cricketer”);// concat() method append String at the end
    System.out.println(s);
  }   

Output:

Indian Cricketer

Using concat() method:

  concat() method concates the specified string to the end of current string.

Class ConcatenateDemo3
{
  public static void main(String args[])
  {
  String s1=“indian”;
  String s2=“Cricketer”;
  String s3=s1.concat(s2);
  System.out.println(s3); //Indian Cricketer
  }
}

Output:

Indian Cricketer




Subscribe us on Youtube

Share This Page on


Ask Question