how to make a string java
String newString = "Hello World";
string manipulation java
String manipulations:
charAt(indexNumber): it returns the char at the given index
length(): returns the total number of characters as int
length is ALWAYS one unit above the maximum index number
maxIndex: length()-1;
concat(Value): Concatenation, concats the given value to the
String and returns a new value
toLowerCase(): converts to lowercase and returns a new String
toUpperCase(): converts to uppercase and returns a new String
trim(): removes the unused spaces , and returns new String
substring(beginning index, ending index):
creates substring of the string value from the beginning index
till the ending
substring(beginning index):
creates substring of the string value from the beginning index
till the end of the stringreplace(old Value, new Value): new value
will be replaced with ALL the given old value, and returns new string
replaceFirs(old Value, new Value):
new value will be replaced with the very first given old value,
and returns new string
indexOf(Value):
returns the index number of the first occurred character as an int
indexOf(Value): returns the index number of first
occurred character,as int
lastIndexOf(Value): return the index number of
last occurred character, as int
isEmpty(): identifies if the string is empty
true ==> string is empty,
false ==> String is not empty
equals(str): checks if two string' visible texts are equal or not
cares about the case sensitivity
A == a ==> false
equalsIgnoreCase(str): checks if two string' visible texts
are equal or not
does not care case sensitivity
A == a ==> true
contains(str): checks if the str is contained in the string.
returns boolean
if str is conatined ==> true
otherwise ==> false
startsWith(str): checks if the string starts with the given str.
returns boolean
if starts with str ==> true
otherwise ==> false
endsWith(str): checks if the string ended with the given str.
returns boolean
if ended with str ==> true
otherwise ==> false
string method example in java
public boolean contains(“searchString”)
String x = “Java is programming language”;
System.out.println(x.contains(“Amit”)); // This will print false
System.out.println(x.contains(“Java”)); // This will print true
string method example in java
public String substring(int begin)/ public String substring(int begin, int end)
------------------------------------------------------------------------------
String x = "0123456789"; // the value of each char is the same as its index!
System.out.println( x.substring(5) ); // output is "56789"
System.out.println( x.substring(5, 8)); // output is "567"
string method example in java
public int length()
-----------------------
String x = "01234567";
System.out.println( x.length() ); // returns "8"
string method example in java
public char charAt(int index)
-----------------------------
String x = "airplane";
System.out.println( x.charAt(2) ); // output is 'r'
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us