Breaking News

Search This Blog

Sunday, December 16, 2018

Java String using it's function - Programming Examples

Java String using it's function - Programming Examples


String is the most widely used square in Java programming. This is the reason that string programs are used in Java interviews to reach coding skills.

example:
  1. char[] ch={'j','a','v','a','t','p','o','i','n','t'};  
  2. String s=new String(ch);  
is same as:
  1. String s="javatpoint";  

Java string provides several methods for class string operation, such as comparison (), concat (), equal (), partition (), length (), replace (), compare (), intern (), substring () e.t.c.

जावा स्ट्रिंग क्लास स्ट्रिंग पर ऑपरेशन करने के लिए कई तरीके प्रदान करता है जैसे तुलना (), concat (), बराबर (), विभाजन (), लंबाई (), प्रतिस्थापित करें (), तुलना करें (), intern (), substring () आदि।




Java String Example

String Change Case

public class StringChangeCase {

public static void main(String[] args) {

String str = "Hello World";

String strLower = str.toLowerCase();
String strUpper = str.toUpperCase();

System.out.println("Original String: " + str);
System.out.println("String changed to lower case: " + strLower);
System.out.println("String changed to upper case: " + strUpper);
}
}

output

Original String: Hello World
String changed to lower case: hello world
String changed to upper case: HELLO WORLD

Java String class methods

The java.lang.String class provides many useful methods to perform operations on sequence of char values.
No.MethodDescription
1char charAt(int index)returns char value for the particular index
2int length()returns string length
3static String format(String format, Object... args)returns a formatted string.
4static String format(Locale l, String format, Object... args)returns formatted string with given locale.
5String substring(int beginIndex)returns substring for given begin index.
6String substring(int beginIndex, int endIndex)returns substring for given begin index and end index.

No comments:

Post a Comment