Sep 26

Write a java program to find duplicate numbers in array or list?

This is one of the frequently asked interview question in interview.So lets begin writing the program by writing the pseudo code.

Pseudo Code :

1) Create a new empty hashmap.

2) This map is used to store the values and the number of times it got repeated.

3) Loop through each value in array and check whether that value is present in map or not.

4) If that value is present in map increment the count.otherwise store that value with count 1.

5) Finally loop through the map and print the values which are greater than 1 which will give you the list of duplicate values. Continue reading

Sep 25

How to remove html tags from String in java?

Remove HTML tags from String in java

This tutorial explains how to remove html tags from a string in java.For example I have a string with html tags and i want only content between tags.

String htmlString=”<head>welcome to java Interview questions website</head> “;

In the above string if we want only content by remove tags, we can use regular expressions to do the same. Continue reading

Jan 11

Write a java program to Create a new file using file.separator in java

File.separator is used to obtain the local computer’s proper separator character instead of explicitly using / or . For example On a Windows computer, the separator character is a backslash ().
On a Linux or Mac OS X system, it’s a forward slash (/).
File.separator is a String consisting of one character—the proper separator for the system. Continue reading

Dec 11

Java example to convert String to Boolean in java?

public class StringToBooleanDemo {

	public static void main(String[] args) {

		//Create a new string object and assign value true to str

		String str="true";

		//Create a new Boolean Object
		Boolean bool=new Boolean(str);

		//Print the value in console

		//Use Boolean class static method valueOf which will convert string to
		//Boolean and return Boolean object

		Boolean bool1=Boolean.valueOf(str);

		//Print the value in console



Dec 10

How to convert String to BigDecimal in java?

To convert String to BigDecimal in java use BigDecimal Constructor.The below example demonstrates how to convert String to BigDecimal in java.

import java.math.BigDecimal;

public class StringToBigDecimal {

	public static void main(String[] args) {

		String string="100.00";
		BigDecimal bigDecimal=new BigDecimal(string);
		System.out.println(" Printing BigDecimal Value "+bigDecimal);




Output :

Printing BigDecimal Value 100.00