Reverse an Array in Java

In this article, we will discuss how to reverse an array in Java. So, if we provide an array of [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] to the program, the output will be an array with elements in reverse order, i.e. [10, 9, 8, 7, 6, 5, 4, 3, […]

25+ Java pattern programs for printing Number, Character Patterns

In Java, we can use for loop, while loop or do-while loops to print different number, alphabets or star patterns programs. The following programs demonstrate the same by creating triangle, rectangle or other patterns.   You may also like : Java Character Pattern Programs   Coding Interview Questions for Java Programmers   Java Tutorial   […]

Java program to find longest substring of given string

In this article, we will see java programs to find the longest substring of a string without repeating characters. For example, longest substring of “hello” without repeating characters will be “hel”. So, length of longest sub-string will be 3. import java.util.HashSet; public class Example {   public static void main(String[] args) {     String s = "hello"; […]

Java program to check if a String is rotated version of another String

In the following Java program, we will check if one String can be obtained by rotating characters of another String. For example, following Strings can be obtained by rotating letters of word “hello”: elloh llohe lohel Here is the Java code for the same : package com.topjavatutorial; public class Demo {   public static void main(String[] […]

Java program to find duplicate characters in a string

In this program, we will check for duplicate characters in a String and count the number of times each character is repeated using Java. package com.topjavatutorial; import java.util.HashMap; import java.util.Map; public class Demo {   public static void main(String[] args) {     String str = "topjavatutorial";     int count = 0;     char c;     Map<Character, Integer> map = new […]