• 13 May

    Java String endsWith example

    String’s endWith method checks if String ends with specific suffix. It returns boolean datatype. Method syntax: public boolean endsWith(String suffix) String endsWith Example: package org.arpit.java2blog; public class StringEndsWithExample { public static void main(String[] args) { String str = "java2blog"; if (str.endsWith("blog")) { System.out.println("String ends with blog"); } else { System.out.println("String does not end with blog"); […]

  • 12 May

    Java String startsWith example

    String’s startsWith method checks if String starts with specific prefix. It returns boolean datatype. Method Signature: public boolean startsWith(String prefix) String startsWith Example: package org.arpit.java2blog; public class StringStartsWithExample { public static void main(String[] args) { String str = "java2blog"; if (str.startsWith("java")) { System.out.println("String starts with java"); } else { System.out.println("String does not start with java"); […]

  • 12 May

    Java String charAt example

    String’s charAt method returns char value present at specified index. String is nothing but Sequence of char values and it starts with index 0. Method Signature: public char charAt(int index) String charAt Example: package org.arpit.java2blog; public class StringCharAtMain { /* * @Author : Arpit Mandliya */ public static void main(String args[]) { String str="java2blog"; System.out.println("char […]

  • 11 May

    Java String trim example

    String’s trim method is used to remove leading and trailing space. Sometimes, you get extra leading or trailing space and your program does not work as expected. It returns String object after removing leading and trailing spaces. String’s trim method does not remove middle spaces. String trim example: package org.arpit.java2blog; public class StringTrimExample { public […]

  • 10 May

    How to check if two Strings are Anagrams in Java

    In this post, we will see how to check if two Strings are Anagrams in java. Anagrams mean if two Strings have the same characters but in a different order. For example: Angel and Angle are anagrams There are many ways to check if Strings are anagrams in java. Some of them are: [toc] Using […]

  • 10 May

    Java String regionMatches example

    String’s regionMatches is used to compare substring of one string to substring of another.Here region may be refer to substring of String, so we are comparing regions of one string with another. Method Syntax:  There are two overloaded version of regionMatches:  // Case sensitive public boolean regionMatches(int toffset, String other, int ooffset, int len): // […]

  • 10 May

    Java String isEmpty example

    String’s isEmpty method checks if length of string is 0 or not. It returns true if length of String is 0 else return false. Method Signature: public boolean isEmpty() String isEmpty Example: package org.arpit.java2blog; public class StringIsEmptyExample { /* * @Author : Arpit Mandliya */ public static void main(String[] args) { String str1=""; String str2="java2blog"; […]

  • 09 May

    Java String length example

    String’s length method is used to calculate length of String. It returns number of character in the String. Method Signature: public int length() String length Example: package org.arpit.java2blog; public class StringLengthExample { /* * @Author: Arpit Mandliya */ public static void main(String[] args) { // 1st String str1 = "Hello world from java2blog.com"; // 2nd […]

  • 08 May

    Java Program to find duplicate Characters in a String

    In this post, we will see how to find duplicate Characters in a String. Approach: Create a HashMap and character of String will be inserted as key and its count as value. If Hashamap already contains char,increase its count by 1, else put char in HashMap If value of Char is more than 1, that means it […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.