String Introduction

String Class

  • String is a class in java that is final
  • String in Java programming, are a sequence of characters. In the Java programming language, strings are objects.
  • String is also a data type in java
  • All string literals in Java programs, such as "abc", are implemented as instances of this class.
  • Strings are constant; their values cannot be changed after they are created
Example of String
String a="Hello";
String b=new String();
String c=new String("Hello");
			
String Handling
Another Example of String
			
String a="Hello";
String b="Hello";
String c=new String("Hello");
if(a==b)
System.out.println("Same reference");

if(a==c)
System.out.println("Same Reference of A and C");
else
System.out.println("Not Same Reference");
			
			
String Memory Management

String Methods

  1. concat(String a):Concate one string content into another string.
  2. Example:
    	String a="Hello";
    	System.out.println(a.concat("Bye");  //Output is HelloBye
    	System.out.println(a);  //Output is Hello
  3. toLowerCase():Convert String into small case.
  4. Example:
    String a="Hello";  
    	a=a.toLowerCase();  // a value is hello
  5. charAt(int index):Returns the character located at the specified index.
  6. Example:
    String a="Hello";
    	System.out.println(a.charAt(1));  //output is e
  7. equalsIgnoreCase(String a):Determines the equality of two strings, ignoring case.
  8. Example:
    String a="Hello";
    	String b="HELLO";
    	if(a.equalsIgnoreCase(b))
    		System.out.println("Equals");
    	else
    	System.out.println("Not Equals");	
  9. split():J2SE 1.4 added the split() method to the String class to simplify the task of breaking a string into substrings, or tokens.
  10. Example:
    String a="This is a String Object";
    String x[]=a.split(" ");
    for(i=0;i<x.length;i++){
    System.out.println(x[i]);
    }
    }