Skip to main content

Methods of String in java

 String in Java

String:  A Java string is a sequence of characters that exist as an object of the class java. lang.

Here is the list of important methods available in the java string class:

Ø startsWith(): It checks if the string starts with the given prefix. If yes then return true else false.


Ø endsWith(): It checks if the string ends with the given suffix. If yes then return true else false.


Ø substring(int begin index) : It returns the substring of the string. The substring starts with the character at the specified index.


Ø  substring(Int begin index , int end index) : Returns the substring. The substring starts with the character at begin index and ends with the character at end index.

Ø toLowerCase() : It converts all the characters of the string into lower case(Small Letters). 



Ø toUpperCase() : It converts all the characters of the string into upper case(Capital Letter). 


Ø indexOf() : It returns the position of the first occurrence of the specified character or string in a specified string. 


Ø lastIndexOf() : It return the last index of the given character. 


Ø isEmpty() : This method return true if the given string has 0 length. 


Ø length() : It returns the length of a string. 


Ø equals() : Compare both the strings and return true if both matches else false. 


Ø equalsIgnoreCase() : It works the same as equals but it does a case insensitive comparison. 


Ø charAt() : It returns the character at the specified index number. 


Ø trim() : It returns the substring after eliminating leading and trailing white space from the original string. 




Ø concat() : Concatenates the specified string at the end of the string. 


 

Ø contains() : It checks whether a string contains the specified sequence of a character value. If yes then it returns true else false. 

Ø replace() : it returns a string after replacing all old characters with a new character.  

 

 

 


 

 

Comments

Popular posts from this blog

Switch Statement In Java

Switch Statement:  The switch statement is just like if-else-if ladder statement. It executes one statement from multiple conditions. It works with a byte, short, int, long, and String. In other words, we can say the Switch case statement is a substitute for a long if statement that compares to several integral values. Syntax of Switch statement in java Enhance Switch or Switch With Arrow: The new syntax uses the -> operator instead of the colon we're used to with switch statements. Also, there's no break keyword. Another addition is the fact that we can now have comma-delimited criteria. Syntax of Enhance Switch in java  

Variables and Data types in Java

  MY PROGRAMMING PARADISE Variables: Variables are used to store data in a computer’s memory. In other words, we can say, variables are just like a container that holds the value while the java program executed. There are three types of variables in java: 1-  Local 2-  Instance 3-  Static   Rules for declaring identifier (Variable name) 1-  All identifiers must begin with a letter, currency character, or underscore. 2-  Blank spaces are not allowed. 3-  An identifier name is case-sensitive. 4-  A keyword cannot be used as an identifier.   Declaring variables: byte age = 28; short salary =32500; float price = 25.50f; char name = ‘v’; boolean flag=true;   Data types: There are two types of data types in java. 1-  Primitive Data type 2-  Non- primitive Data types   Primitive Data type: There are mainly eight types of primitive data types: Types Size Range Default Value byte 1 Byte [-128, 127] 0 short 2 Byte [-32,768 , 32...

Conditional Statements In Java

  Conditionals Statement   A conditional statement  is a set of rules performed if a certain condition is met. A conditional statement begins with the keyword if followed by parentheses. The result of the evaluation is true or false. ·       ‘ if ‘ statement ·       ‘ if-else ‘ statement ·         Nested ‘ if ‘ statement ·       ‘ if-else - if ‘ statement IF statement: ‘IF’ statement is the most basic and simple statement among all the statements. For example- if a value is less than 0, return “Negative value”. Let’s see an example- IF-ELSE statement: The if-else is statement is an extended version of If. Let’s see an example- Nested IF-ELSE statement : In Java, when there is an if statement inside another if statement then it is known as nested if-else. Let’s see an example- IF-ELSE-IF: ‘ if-else-if ’ statement is used when we need to check mul...