java

java

Java program to find the duplicate elements in an array of Strings

In this tutorial, we will learn how to find duplicate elements in an array of strings. We will learn this using two different approaches :.

Read
java

Java program to find count of words and find repeating words in a String

In this tutorial, we will learn how to print the count of each word in a string using Java. The user will first enter the string and then we will find the count and print out the result.

Read
java

Java program to count the occurrence of each character in a string

In this tutorial, we will learn how to count the occurrence of each character in a String. The user will enter one string and we will count the occurrence of each character in that string. We will use one HashMap to store the character and count for that character. The key of that hash map is Character and value is Integer. Let's take a look at the Java program first :.

Read
java

Java program to replace string in a file

In this tutorial, we will learn how to read strings from a file, how to modify the contents and then again write them back in the same file. We are not taking any inputs from the user. In this example, after reading the contents of the file, we are replacing all 'new' words with 'old'. For example, if the file contain one string This is a new ball., after modification it will become This is a old ball. Let's take a look into the program before moving into more details :.

Read
java

Java program to convert a string to boolean

In this example, we will learn how to convert a string to boolean value. For that, we will use one static method valueOf(String) of the Boolean class. This class is defined as below :.

Read
java

Java program to capitalize first letter of each word in a string

In this tutorial, we will learn how to capitalize first letter of each word in a string in Java. User will input one string and then we will capitalize first letter of each word and modify and save the string in a different String variable. Finally, we will output the String.

Read
java

Java ListIterator set method example

In this example, we will learn how to use ListIterator in Java . ListIterator is an interface that extends Iterator interface. Using it, we can iterate a list in either direction. During the iteration, we can get the current position of the iterator and the value of the current element.

Read
java

Java program to remove all white space from a string

In this tutorial, we will learn how to remove all blank characters (like whitespace,tabs,newline etc) from a string. We will learn two different methods to achieve this.

Read
java

Java program to find the sum of all digits of a number

In this tutorial, we will learn how to find the sum of all digits of a number in Java. Algorithm we are using is as below :.

Read
java

Java program to calculate the area and perimeter of a rectangle

In this tutorial, we will learn how to find the area and perimeter of a rectangle. To find the area and perimeter, we need only height and width of the rectangle. Area of a rectangle is 'height * width' and perimeter is ' 2* ( height + width )' .

Read