Contact Us || Privacy Policy || About Us |
|
What is String in Java→ String is a sequence of characters, in double quotation mark. → String an object in java. → String is an array of characters . ExampleHow to create string object:→ There are 2 ways to create String object
1) String Literal→ String Literal contain "double quotes" String Value. ExampleOutput: ![]() 2) new keyword→ When we can create String object using new keyword for that allocates memory for the object. . String class has many constructors to create String objects using different sources, such as string literal, an array of characters etc. ExampleOutput java strings example String Method in JavaThere are some use full Method are used in this chapter that is.
1) Java String length() :-→ length() Method returns count of total number of characters present in the String. Example: Output: ![]() 2) Java String compareTo() :-→ compareTo() method compares the given string with current string. It either returns positive number or negative number or 0. Example: Output: ![]() 3) Java String concat() :-→ concat() method is used to add two or more string into a single string object.or You can say append of another string. Example: Output: ![]() 4) Java String IsEmpty() :-→ IsEmpty() method checks string is empty or not. If the java String is Empty, it returns true otherwise else returns false. Example: Output: ![]() 5) Java String Trim() :-→ Trim() Method Remove whitespace from both sides of a string: Example: Output: ![]() 6) Java String toLowerCase() :-→ toLowerCase() method converts all the characters of the String in lower case letter. Example: Output: ![]() 7) Java String toUpper() :-→ toUpper() converts all the characters of the String in Upper case letter. Example: Output: ![]() 8) Java String ValueOf() :-→ ValueOf() Method converts different types of values into string such as long to string, boolean to string, character to string, float to string, double to string, object to string and char array to string etc. String valueOf() method in Java
Example: Output: ![]() |