1. String represents group of “characters”.
  2. In C/C++ languages,a string represents an array of characters,Where the last character will be http://www.grecorailings.com/?fartyx=%D8%AA%D8%AF%D8%A7%D9%88%D9%84-%D8%A7%D9%84%D8%B3%D9%88%D9%82-%D8%A7%D9%84%D8%B3%D8%B9%D9%88%D8%AF%D9%8A-%D9%84%D9%84%D8%A3%D8%B3%D9%87%D9%85-%D9%85%D8%A8%D8%A7%D8%B4%D8%B1&2b4=47 تداول السوق السعودي للأسهم مباشر ‘\0’(null character).
  3. http://snelnaarschiphol.nl/?fantomas=migliori-strategie-forex&23e=a7 migliori strategie forex Example:In C/C++,” http://webhostingandbeyond.com/?kiir=%D8%A7%D9%84%D8%B3%D9%88%D9%82-%D8%A7%D9%84%D8%A7%D8%B3%D9%87%D9%85-%D8%A7%D9%84%D8%B3%D8%B9%D9%88%D8%AF%D9%8A%D8%A9-%D8%A7%D9%84%D9%8A%D9%88%D9%85 السوق الاسهم السعودية اليوم JAVA” is internally represented by
    J A V A \0

    But this is not valid in java.

  4. String is not a character array.In java,We have both “character array” as well as “String”.

توصيات فوريكس Creating Strings:

  1. We can create a String by assigning a group of characters to a String type variable.
    String s;//declare String type variable
    s="JAVA";//Assign a group of characters to it.
    

    http://www.inehd.org/?rupx=optionrally-%D8%B4%D8%B1%D9%83%D8%A9&e5e=71 optionrally شركة (OR)

    String s="JAVA";
    
  2. We can create an object String class by using new operator.
    String s=new String();
    String s=new String("Hello");
    String s=new String(String s);
    
  3. We can create String by converting ‘char’ array into Strings.
    char[] ch={'A','B','C','D'};
    String s=new String(ch);
    
  4. It copies all characters from array to String.If we don’t want all the characters of the array into String.Then we can mention which characters we need.
    class Test {
    public static void main(String[] args) {
    char[] arr={'H','y','d','e','r','a','b','a','d'};
    String s=new String(arr,2,3);
    System.out.println(arr);
    System.out.println(s);
    /*output:
    hyderabad
    der
    */
     }
    }
    

    Here,Starting from 2nd characters a total of 3 char’s are copied into the String s

  5. We can create String by converting ‘byte’ array into Strings.
    byte[] b={100,101,102};
    String s=new String(b);
    System.out.println(s);//def
    
  6. String s=new String(int[],int offSet,int Count);
    
  7. String s=new String(byte[],int offSet,int Count);
    
  8. String s=new String(StringBuilder sb);
    

موقع تجارة الاسهم Important methods of String class

  1. مكاتب توصيات اسهم char charAt(int index)
    Returns the char value at the specified index

    String s="JAVA";
    System.out.println(s.charAt(0));//J
    System.out.println(s.charAt(2));//V
    System.out.println(s.charAt(5));//StringIndexOutOfBoundsException
    
  2. http://thebell-hotel.org/?minus=%D8%B4%D8%B1%D9%83%D8%A9-%D8%A7%D9%84%D8%B3%D9%88%D9%82-%D8%A7%D9%84%D9%85%D8%A7%D9%84%D9%8A%D8%A9-%D8%A7%D9%84%D8%B3%D8%B9%D9%88%D8%AF%D9%8A%D8%A9&300=5d شركة السوق المالية السعودية int codePointAt(int index)
    Returns the character unicode at the specified index.

    class Test{
     public static void main(String args[]){
      String s="JAVA";
      System.out.println(s.codePointAt(1));
     }
    }
    /*
    output:65
    */
    
  3. weizmann forex limited jalandhar punjab string concat(String str)
    Concatenates the specified String to the end of this String

    class Test{
     public static void main(String args[]){
       String s="Arch";
       s=s.concat("Technologies");
       System.out.println(s);
     }
    }
    /*
    Output:ArchTechnologies
    */
    

    اسهم بنك الوطني Note:The same concatenation can be done by using ‘+’ operator which is called “String Concatenation operator”

    class Test{
    public static void main(String args[]){ 
    String s="Arch";
     s=s+"Technologies";
     System.out.println(s);
    }
    }
    /*
    Output:ArchTechnologies
    */
    
  4. forex kolkata salt lake int length()
    Returns the length of a given String
    مواقع الاسهم السعودية Example:

    class Test{
     public static void main(String args[]){
      String s="JAVA";
      System.out.println(s.length());
     }
    }
    /*
    Output:4
    */
    
  5. اسعار اسهم اتصالات الامارات int compareTo(String s)
    This is method is useful to compare two strings and to know which string is bigger or smaller
    zarabianie na kursie walut Example:

    public class Test 
    {
    public static void main(String args[])
    {
    String s1 = "Arch";
    String s2 = "Arch";
    String s3 = "ArchTechnologies";
    int result = s1.compareTo( s2 );
    System.out.println(result);
    result = s2.compareTo( s3 );
    System.out.println(result);
    result = s3.compareTo( s1 );
    System.out.println(result);
    }
    }
    /*
    output:
    0
    -12
    12*/

    ما معنى تم تداوله بمحفظتة الأسهم Note:

    1. If s1=s2,it returns 0.
    2. if s1>s2 then it retuns +ve number.
    3. if s1
  6. تحليل سوق دبي للاسهم int compareToIgnoreCase(String s)
    This method is same as “compareTo()” method,but this method is not case sensitive.
    that means “Box” and “box” are equal.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String s1 = "ARCH";
    String s2 = "Arch";
    String s3 = "ArchTechnologies";
    int result = s1.compareToIgnoreCase( s2 );
    System.out.println(result);
    result = s2.compareToIgnoreCase( s3 );
    System.out.println(result);
    result = s3.compareToIgnoreCase( s1 );
    System.out.println(result);
    }
    }
    /*
    output:
    0
    -12
    12
    */
    
  7. boolean equals(String s)
    This method returns true, if two strings are same other wise it returns false.It is case sensitive.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String s1 = "ARCH";
    System.out.println(s1.equals("arch"));
    System.out.println(s1.equals("ARCH"));
    }
    }
    /*
    output:
    false
    true
    */
    
  8. boolean equalsIgnoreCase(String s)
    This method returns true, if two strings are same other wise it returns false.It is case not sensitive.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String s1 = "ARCH";
    System.out.println(s1.equalsIgnoreCase("arch"));
    System.out.println(s1.equalsIgnoreCase("ARCH"));
    }
    }
    /*
    output:
    true
    true
    */
    
  9. boolean startsWith(String prefix)
    This method returns true,If a String is beginning with the sub string
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String s3 = "ArchTechnologies";
    System.out.println(s3.startsWith("Arch"));
    }
    }
    /*
    output:true
    */
    
  10. boolean endsWith(String suffix):-
    This method returns true .If a String ends with subString.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String s3 = "Arch Technologies";
    System.out.println(s3.endsWith("Technologies"));
    }
    }
    /*output:
    true*/
    
  11. int indexOf(String s)
    This method retuns the index of 1st occurance of specified String.
    Example:

    public class Test 
    {
    public static void main(String args[])
    {
    String s3 = "ArchTechnologies";
    System.out.println(s3.indexOf("Arch"));
    System.out.println(s3.indexOf("software"));
    }
    }
    /*
    output:
    0
    -1
    */
    

    Note:

    1. If the specified String is not available,then this method returns -1.
    2. If the specified String is available,then this method returns 0.
  12. int lastIndexOf(String s)
    This method returns the index of last occurance of specified String.
    Example:

    public class Test {
    public static void main(String args[]) {
    String s3 = "This is a book";
    System.out.println(s3.lastIndexOf("is"));
    System.out.println(s3.indexOf("is"));
    }
    }
    /*output:
    5
    2
    */
    
  13. String subString(int i)
    This method is useful to extract substring from a main String.It returns the new String consisting of all characters from the position ‘i’ untill end of a String.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String S3 = "Hyderabad";
    System.out.println(S3.subString(4));
    }
    }
    /*
    output:
    rabad 
    */
    
  14. String subString(int i1,inti2)
    This method returns a new String consisting of all char’s Starting from i1 to i2.The character at i2 is executed
    Example:

    public class Test
    {
    public static void main(String args[]) 
    {
    String S3 = "Hyderabad";
    System.out.println(S3.subString(2,5));
    }
    }
    /*
    output:
    der*/
    
  15. String toLoweCase():-
    This method converts all characters of the String into lowercase and retuns that lower-cased String.
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String S3 = "Arch";
    System.out.println(S3.toLowerCase());
    }
    }
    /*
    output:
    arch */
    
  16. String toUpperCase()
    This method converts all characters of the String into UpperCase and retuns that upper-cased String.
    Example:

    public class Test {
    public static void main(String args[]) {
    String S3 = "Arch";
    System.out.println(S3.toUpperCase());
    }
    }
    /*
    output:
    ARCH */
    
  17. String trim()
    This method removes the spaces present at beginning and ending of the String but not middle blank spaces.
    Example:

    public class Test {
    public static void main(String args[]) {
    String S3 = "   best training Institute     ";
    System.out.println(S3.trim());
    System.out.println(S3);
    }
    }
    /*output:
    best training Institute
          best training Institute 
    */  
    
  18. void getChars(int i1,int i2,char arr[],int i3)
    This method copies characters from a String into a char array.The characters starting from position ‘i1’ to ‘i2-1’ in the String are copied into the arr to a location Starting from i3
  19. String[] split(delimiter)
    This method is useful to break a String into pieces by using delimeter,the resultant pieces are returned into a String type array
    Example:

    String s1="This,is,java";
    String[] s2=s1.split(",");
    }
    }
    
  20. String replace(char c1,char c2 )
    This method replace all the occurrences and character ‘C1’ by a new character ‘c2’
    Example:

    public class Test 
    {
    public static void main(String args[]) 
    {
    String S3 = "ArmhTemhnologies";
    System.out.println(S3.replace('m','c'));
    }
    }
    /*output:
    ArchTechnologies
    */
    
  21. String replaceAll(String regex,String replacement)
    This method replaces each sub String of this String that matches with Given replacement.
    Example:

    public class Test{
    public static void main(String args[]){
    String S3 = "Welcome to Arch";
    System.out.println(S3.replaceAll("Arch","ArchTechnologies" ));
    }
    }
    /*output:
    ArchTechnologies
    */
    
  22. boolean isEmpty()
    This method returns true,When the String length is 0,otherwise returns false.
    Example:

    public class Test {
    public static void main(String[] args) {
    String S3 = "";
    String s2="ArchTechnologies";
    System.out.println(S3.isEmpty());
    System.out.println(s2.isEmpty());
    }
    }
    /*output:
    true
    false
    */
    
  23. String intern()
    This method represent canonical form
  24. static String format(String format,object…args)
    Returns a formatted String using the specified format String and arguments
    The format characters supported by System.out.printf()
    are also usable with format() method
    Example:

     
    public class Test 
    {
    public static void main(String[] args) 
    {
    int i=65;
    String s = "Hai";
    char ch='A';
    String s2=String.format("i=%d%n s=%s%n ch=%c",i,s,ch);
    System.out.println(s2);
    }
    }
    /*
    output:
    i=65
    s=Hai
    ch=A*/
    

What is Object reference?
Object reference is a unique hexadecimal number representing the memory address of the object .it is useful to access the members of the object.

class Demo {
}
public class Test {
public static void main(String args[]) {
Demo d=new Demo();
System.out.println(d);
}
}
/*
output:
Demo@4daa34dc
*/
  1. When an object is created by JVM,it returns the memory address of the object as a ‘hexadecimal’ number which is called object reference.
  2. that means, every object will have a unique reference.

String comparison

Class StrCompare{
Public static void main(string args[]){
String S1=new String(“Arch”);
String S2=new String(“Arch”);
If (S1==S2)
System.out.println(“both are same”);
Else
System.out.println(“not same”);
}
}
/*
output:not same
*/
  1. Actually , we should compare the contents of the string objects , not their references .this is the reason ==is not used to compare the string.
  2. To compare the contents of the string objects we should use ‘equals’ method.
  3. Class StrCompare{
    Public static void main(string args[]){
    String S1=new String(“Arch”);
    String S2=new String(“Arch”);
    If(S1.equals(S2))
    System.out.println(“same”)
    else
    System.out.println(“Not same”)
    }
    }
    /*
    Output:same
    */
    

    what is the difference between”==”and “equals()” while comparing strings?
    ==” operators compares the reference of the string objects. It does not compare the contents of the objects. where as “equals()” method compares the contents of the string.
    what is the string constant pool?
    String constant pool is a separate block of memory where the string objects are held by JVM. If a string object is created directly using assignment operator

    Example:

    String s="Arch";
    

    In this case only one object (string) will be created in String constant pool and s will be refer that object.

  4. String s=new string(“Arch”);
    In this case 2 objects will be created one is in heap and the other one is in string constant pool. and s always refers to heap object.
    For every string constant literal compulsory one object should be created in string constant pool.

Explain the difference b/w the following two statements

  1. String s=”Arch”;
  2. String s=new String (“Arch”);

  1. In the first statement, assignment operator is used to assign the string literal to the String Variables.

    In this case, JVM first of all checks the same object is already available in the string constant pool.
    If it is available, then it creates another reference to it. If the same object is not available then it creates another object with the content “Arch” and stores it into the string constant pool.

  2. In the second statement, new operator is used to create the String object. In this case, JVM always creates a new object without looking into String constant pool.
class Test{
public static void main(String args[]){
String s1=new String("Arch");
String s2="Arch";
String s3=new String("Arch");
String s4="Arch";
System.out.println(s2==s4);
System.out.println(s2.equals(s4));
System.out.println(s1==s3);
System.out.println(s1.equals(s3));
}
}
/*
output:
true
true
false
true
*/

Example:

public class Test {

  public static void main(String[] args) {
  String s1="you cannot change me!";
  String s2=new String("you cannot change me!");
  System.out.println(s1==s2);
  String s3="you cannot change me!";
  System.out.println(s1=s3);
  String s4=new String("you cannot change me!");
  System.out.println(s2==s4);
  String s5="you cannot";
  String s6=s5+"change me!";
  System.out.println(s1=s6);
  String s7="you cannot"+"change me!";
  System.out.println(s1==s7);
  final String s8="you cannot";
  String s9=s8+"change me!";
  System.out.println(s1==s9);
  
 }
}
/*
output:
false
you cannot change me!
false
you cannot change me!
false
false
*/

Immutability of Strings

We can divide objects broadly as mutable and immutable objects.

  1. mutable object:
    mutable objects are those objects whose contents can be modified.
  2. immutable Object:
    immutable objects are those objects,once created can not be modified and String class objects are immutable objects.
public class Test
{
public static void main(String[] args) 
{
String s1=new String("arch");
s1.concat("tech");
System.out.println(s1);
}
}
/*output:
arch
*/

Once we created a String object we are not allowed to change it’s content.If we are trying to change ,with those changes a new String object will be created.This behaviour is nothing but “immutability” of the String Object.

public class Test
{
public static void main(String[] args) 
{
String s1=new String("arch");
s1=s1.concat("tech");
System.out.println(s1);
}
}
/*output:
archtech
*/

Interning of the String objects

If we know heap object reference we can find equivalent String constant pool object reference by using intern() method.
Example:

public class Test
{
public static void main(String[] args) 
{
String s1=new String("arch");
String s2=s1.intern();
String s3="arch";
System.out.println(s2==s3);
}
}
/*
output:
true
*/

If the equivalent object is not available in String constant pool then intern() method itself create equivalent object in string constant pool
Example:

public class Test
{
public static void main(String[] args) 
{
String s1=new String("arch");
String s2=s1.concat("technologies");
String s3=s2.intern();
String s4="arch technologies"
System.out.println(s3==s4);
}
}
/*output:
true
*/

Example:

public class Test
{
public static void main(String[] args) 
{
String s1="spring";
String s2=s1+"summer";
s1.concat("fall");
s2.concat(s1);
s1+="winter";
System.out.println(s1);
System.out.println(s2);
}
}
/*output:
sprinwinter.
springsummer.*/

Because of some runtime operation,If an object is required to create compulsary that object will be created only in the heap.
Example:

public class Test
{
public static void main(String[] args) 
{
String s1="arch";
String s2=s1.toUpperCase();
String s3=s1.toLowerCase();
System.out.println(s1==s2);
System.out.println(s1==s3);
}
}
/*
output:
false
true
*/

After applying any method on the String object if There is no change in the content then no new String object will be created.If there is any change in the content,with those changes a new String object will be created.