In this we are going to learn about Strings in Java
- The String class is immutable (constant), i.e. Strings in java, once created and initialized, cannot be changed.
- The String is a final class, no other class can extend it, and you cannot change the state of the string.
- String values cannot be compare with '==', for string value comparision, use equals() method.
- String class supports various methods, including comparing strings, extracting substrings, searching characters & substrings, converting into either lower case or upper case, etc.
- The string examples given below describes more on string functionlaity.
The follwoing example expalin's about different way's of string initilization
package com.onlinecodegeek.javase;public class StringInitializationEx { public static void main(String a[]){ String str1 = "This is a string object"; String str2 = new String("this is also string object"); char[] c = {'a','b','c','d'}; String str4 = new String(c); String str5 = str1+" This is another String object"; System.out.println("str1"+str1); System.out.println("str2"+str2); System.out.println("str4"+str4); System.out.println("str5"+str5); }}| str1This is a string object str2this is also string object str4abcd str5This is a string object This is another String object |
0 comments :
Post a Comment