String toUpperCase example

String toUpperCase method is used to converts all characters in a given string to upper case. String has 2 toUpperCase methods. [crayon-5f972385ab35e265335354/] The first method takes a default Locale for converting the String to upper case, while in the second method we

Read More

String toLowerCase example

String toLowerCase method is used to converts all characters in a given string to lower case. String has 2 toLowerCase methods. [crayon-5f972385abef7847245559/] The first method takes a default Locale for converting the String to lower case, while in the second method we

Read More

String substring example

String substring method is used to get a part of String using the start and end index. String had 2 substring methods. [crayon-5f972385ac402946769358/] 1. [crayon-5f972385ac40b166897592-i/] returns part of the String from the given start index till the end of the String. If

Read More

String length example

String length method in java is used to get the length of a given string. String length method example [crayon-5f972385aca02440756385/] Output [crayon-5f972385aca0c139882261/] Please Note: Before performing any operation on any dynamically generated String, check if the String is not null. Else a

Read More

String equals and equalsIgnoreCase

String equals and equalsIgnoreCase are used for comparing 2 Strings in java.Both these methods works exactly similar except for equalsIgnoreCase compares String ignoring case consideration. example: We have 2 String as defined below [crayon-5f972385ace97928721680/] Now using [crayon-5f972385aceb1981217741-i/] will result as “false” But

Read More

How to split String in java

String API provides 2 methods to split String in java. [crayon-5f972385ad427901733657/] Both these methods return a array of String that has been split. In this post we will see some examples using both these methods. 1. Split String using split(String regex) In

Read More

How to convert String to long

In Java we have multiple ways to convert String to long. We will see a few of those ways in this post. 1. Convert String to long using Long.parseLong() [crayon-5f972385ad9e1622834841/] If the String value doesn’t contain all digits OR if the String

Read More

How to convert String to Date

In this post we will see how to convert String to date in java. For this we will use SimpleDateFormat API to convert string to date. We need to pass in the dateformat in which we want to convert String to date

Read More

How to compare Strings in java

We can compare Strings in java either using [crayon-5f972385ae616139987549-i/] or [crayon-5f972385ae620773102028-i/] depending on how the String was created. Using == to compare Strings in java == operator will check the reference of the Strings. If the references are same then == will

Read More

How to convert String to boolean

In Java we have multiple ways to convert String to boolean. We will see a few of those ways in this post. 1. Convert String to boolean using Boolean.parseBoolean() For Any value of string other than “true” (case insensitive), parseBoolean() will return

Read More