3 ways: How to Find Duplicate Words in String in Java

In this tutorial, I will be sharing how to find duplicate words in String in Java. There are many ways to solve this problem. One easy way is by using the Collections.frequency() method. Another way is without using the Collections API. I will be sharing both of them. Let's dive deep into the topic:

Read Also:  String Interview Questions and Answers 

First, understand the problem statement by writing some examples:

Examples of Duplicate Words in String are:

Given String: "Java is a programming language. Python is also a programming language."
Duplicate words are : "is","a","programming","language." 
Given String: "Java has 50 keywords in total. Null, true, and false might seem like keywords but they are not in Java"  
Duplicate words are : "keywords", "in", "java"  

Java Program to find Duplicate Words in String

Java Program to Check if a String is a Pangram

In this tutorial, I will be sharing what is Pangram in java, examples of Pangram, algorithm, and java program to check if a given String is a Pangram or not.

Read Also:  How to Check String contains Special Characters in Java 

What is Pangram String in Java

According to Wikipedia,

A String is called Pangram if it is using every letter of a given alphabet at least once. In simple words, if a String contains all the 26 letters of English alphabet at least once.
Examples of Pangram:

Given String: "The quick brown fox jumps over the lazy dog"  
Is Given String Pangram : Yes 
Given String: "The five boxing wizards jump quickly"  
Is Given String Pangram : Yes  

Below are examples of String which are NOT Pangram:

Given String: "Father of Java programming language is James Gosling"  
Is Given String Pangram : No 
List of Missing letters : 'b','c','d','k','q','w','x','y','z' 
Given String: "Do you know how many total keywords present in Java"  
Is Given String Pangram : No 
List of Missing letters : 'b','c','f','g','q','x','z' 

Instance Variable in Java with Example

In this tutorial, I will be sharing what are instance variables in java, example of an instance variable, properties of instance variables in java, and default values for instance variables. Let's dive deep into the topic.

Read Also: Types of Variables in Java

What are Instance Variables in Java?

Instance variables are defined inside a class but outside any method declaration. These variables are defined without the static keyword and are only initialized when the class is instantiated i.e. object of that class is created. These variables belong to each unique object and have scope only within that object i.e not shared among instances.

'Property', 'Instance variable', 'Field', or 'Attribute' are the terms having the same meaning.

Example of Instance Variable in Java

The following code defines instance variables for the empName, empId for employee objects.

public class Employee {
    // Instance variable empName with public access modifier
    public String empName;
    // Instance variable empId with private access modifier
    private int empId;


Each instance of the Employee class can have its own unique values for those two fields.

Remove First and Last Character from String in Java

In this article, I will be sharing different ways to remove the first and last character from String in java. There are 2 ways to achieve the result.

1. Using substring() method
2. Using deleteCharAt(int index)

Let's dive deep into the topic.

Read Also: Difference between String, StringBuilder, and StringBuffer

1. Using substring(int beginIndex, int endIndex) method

substring() method is present in the String class. String class provides two overloaded substring methods but we will use the below method to remove first and the last character from the given String.

substring(int beginIndex, int endIndex)

The above method will create the substring starting from the beginIndex and extends to the character at index endIndex-1. In simple words, substring() will include beginIndex and extends till the end excluding the endIndex.

Since String is immutable i.e once created can not be changed or modified, substring() method will return a new String without first and last character. The length of the new substring() will be endIndex - beginIndex.

public class JavaHungry {
    public static void main(String args[]) {
        // Given String
        String inputString = "JavaHungry";
        // Calculate length of the given String
        int length = inputString.length();
        // Removing first and last character from String
        // Above Code in One line 



Java Basic Programs | Java Programming Examples with Output

Learning Java or any other programming language requires practice. More you practice more you will become comfortable with the syntax of the programming language and get better at coding.
In this post, I will be sharing Java programs on numbers, star patterns, alphabet patterns, and string. This is a good starting point for absolute beginners and beginners.

Read Also: Java Projects for Beginners

After understanding the problem, I recommend trying to solve the program by yourself first. If you face any difficulty then you can take reference from these examples. I suggest writing some examples of the problem statement before coding the java program. By writing examples, it will make sure that you have understood the program correctly.

Java Programs For Beginners

1. Number Programs