Java : Coding Problems

Java : Coding Problems

java2blog.com/java-coding-interview-questions

These are some of the coding problems that seems relevant to me.

Question 4 : How to check if one String is rotation of another String in java? Solution: Let’s say you want to check whether str1 and str2 is rotation of one another or not.

Create a new String with str3= str1 + str1 Check if str3 contains str2 or not. if str3 contains str2 then str2 is rotation of str1 else it is not You can find complete solution at check if one String is rotation of another in java.

Question 3 : Write a program to check if String has all unique characters in java? Solution: Here are some ways to check if String contains all unique characters

By using HashSet Using indexOf and lastIndexOf methods of String By Using ascii value of characters. Please refer to complete solution at check if String has all unique characters.

Question 5 : How to find duplicate characters in String in java? Solution: Here is a solution to find duplicate characters in String.

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 is duplicate character in that String. Please refer to solution at program to find duplicate characters in a String.

Question 6 : Find first non repeated character in String in java? Solution: There are may ways to find it. Some of them are:

Using LinkedHashMap Using indexOf and lastIndexOf methods. Please find complete solution at find first non repeated character in a String.

Question 7 : Find all substrings of String in java?

Solution: Java program to find all substrings of a String. For example: If input is “abb” then output should be “a”, “b”,”b”, “ab”, “bb”, “abb” We will use String class’s subString method to find all subString. Please refer to complete solution at find all subStrings of String.