Showing posts with label Core Java. Show all posts
Showing posts with label Core Java. Show all posts

Enum.ordinal() Method in Java

Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero). For example, let's have weekdays in an enum starting from Monday,...

Find the Occurrences Of Each Character In a String

Find the Occurrences Of Each Character In a String without using collection. Here we are going to create simple array to store the character occurrence. If we look at ASCII value of each character...

Longest palindrome Sub-sequence from the given String using Dynamic Programming

Write a program to find the longest sub-sequence palindrome from the given string by using dynamic programming. For example Input String : ABCDQRDC Longest sub-sequence palindrome: 5  So let's see how we will solve and...

How to create a graph using Java

Let's see simple graph creation using core java and printing all the vertex along with list of edges which goes from that particular Vertex. public class MyGraph { public static void main(String[] args) {...

Reverse words in a given String using recursion

Reverse words in a given String using recursion. We need to reverse words by words in a given line and not the character in a given string. We need to solve this by using...

Rotate matrix by clockwise

Given a NxN matrix and need to rotate by clockwise as given below Examples: Let's see simple java code to rotate given NxN matrix. public class MatrixRotate { private int prev, curr; public static...

Find the smallest window in a string containing all characters of another string (With smallest window)

Given two strings string1 and string2, find the smallest substring in string1 containing all characters of string2 efficiently.For Example: Steps: Generate all substrings which starts with any one character from the pattern string Iterate...

How to find missing number in a sequential array ?

Given a list of sequential integers and need to finding a missing number from the list of numbers. For example if we have an array like Example:1 array = {1,2,3,5,6} Finding missing number 4...

Split the array into two equal Sum subarrays

Given an array of integers greater than zero, find it possible to split it in two subarrays such that the sum of the two subarrays is the same or with minimal difference. Print the...