Search and Replace with Java regular expressions

Sravani S
Published on 12-Feb-2018 10:53:11
Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn.A regular expression is a special sequence of characters that help you match or find other strings or sets of strings, using a specialized ... Read More

Java String intern() method example.

Arjun Thakur
Published on 12-Feb-2018 10:50:29
The intern() method of the String class returns a canonical representation for the string object. It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.ExampleLive Demoimport java.io.*; public class Test {    public static void main(String args[]) {   ... Read More

Java Program to find duplicate characters in a String?

Ayyan
Published on 12-Feb-2018 10:41:10
Following is a Java example which deletes duplicate elements from a given string.Exampleimport java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; public class DuplicateSample {    public static void main(String args[]){       String str = "malayalam";       char[] myArray = str.toCharArray();       for(int i=0; i<myArray.length-1; i++){     ... Read More

Java String indexOf() method example.

Fendadis John
Published on 12-Feb-2018 10:47:30
The IndexOf() method of the String class accepts a character as a parameter and it returns the index of the first occurrence of the specified character. In case if the String does not contain the specified character then it returns -1.ExampleLive Demoimport java.io.*; public class Test {    public static ... Read More

Java String getChars() method example.

Sai Nath
Published on 12-Feb-2018 10:45:32
The getChars() method of a String class accepts four parameters namely − srcBegin − index of the first character in the string to copy. srcEnd − index after the last character in the string to copy. dst − the destination array. dstBegin − the start offset in the destination array.ExampleIt copies all the characters ... Read More

How to test String is null or empty?

V Jyothi
Published on 12-Feb-2018 10:42:28
We can verify whether the given string is empty using the isEmpty() method of the String class. This method returns true only if length() is 0.ExampleLive Demoimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       String str = "tutorialspoint";       // ... Read More

Java String getBytes() method example.

Jai Janardhan
Published on 12-Feb-2018 10:42:08
The getBytes() method encodes the current String into a sequence of bytes using the given charset, storing the result into a new byte array.ExampleLive Demoimport java.lang.*; public class StringDemo {    public static void main(String[] args) {       try {          String str1 = "admin"; ... Read More

Java String format() method example.

George John
Published on 12-Feb-2018 10:39:08
Java provides printf() and format() methods to print output with formatted numbers. The String class has an equivalent class method, format(), that returns a String object rather than a PrintStream object. Using String's static format() method allows you to create a formatted string that you can reuse, as opposed to ... Read More

Java program to find the percentage of uppercase, lowercase, digits and special characters in a String

Akshaya Akki
Published on 12-Feb-2018 10:34:25
Convert the given string into an array of characters for each character of the array verify whether it is upper case, lower case, digit or, any other character using isUpperCase(), isLowerCase(), isDigit() method of the Character class.ExampleLive Demopublic class Sample2 {    public static void main(String args[]) {     ... Read More

Java String equalsIgnoreCase() method example.

Arushi
Published on 12-Feb-2018 10:33:48
The equalsIgnoreCase() method of the String class compares this String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are the equal ignoring case.ExampleLive Demoimport java.lang.*; public class StringDemo {    public ... Read More
Advertisements