Tag: Java
Java – How to Convert String to Long ?
Problem Statement You need to convert a java string to long in your java program. Solution The output of the above program is Abundantcode.com Java Tutorials 75 79
Java – How to calculate of Power of a BigInteger Number ?
Problem Statement You need to calculate the power of a number of type BigInteger in Java. Solution Use the instance method “pow” of the type BigInteger by passing the exponent which will return the power as shown below. The output of the above program is 26665751846889541009
How to convert Array to List in Java ?
This article will explain how to convert a simple array to list in Java . How to convert Array to List in Java ? The Java’s array class provides necessary methods to convert the array to the List using the asList method. Below is a sample code snippet demonstrating the usage of the Arrays.asList method to convert array to List.
Command Line Parsers for Java Developers
There are plenty of command line parsers available for the java developers. Below is the list of some of them. Command Line Parsers for Java Developers JCommando jopt-simple Commons CLI JSAP v2.1: the Java Simple Argument Parser GNU getopt – Java port JArgs Command Line Option Java Gems Natural CLI JewelCli
Java – How to Read Integers from the Console for calculation ?
Problem Statement You need to read integers from the console window and use it for calculation within your java program. Solution If you want to know how to read integer value from a console and use it for calculation , you can use the Scanner class as shown below. The output of the above program is Please enter the first number for abundantcode 10 Please…
Java – How to Convert primitive long datatype to Long object?
Problem Statement You need to convert the primitive long datatype to object in Java. Solution Use the Long wrapper class to convert the long primitive to Long object as shown below. The output of the above program is Abundantcode.com Java Tutorials 89
Java – How to create BigDecimal from string value ?
Problem Statement You want to create a BigDecimal value from a string type in Java. Solution Use the BigDecimal class and pass the string value in the constructor to create the BigDecimal value as shown below. The output of the above program is Abundantcode.com Java Tutorials 198654586.297292792
For Each loop in Java
Java 5 brought in the support in the support for foreach loop that lets the developers to iterate over collections pretty easily. The syntax for the foreach loop in java looks like the one shown below. for (<datatype> item: collection) { // Process the item } For Each loop in Java Below is an example that demonstrates foreach loop in java. package com.abundantcode; import java.util.ArrayList;…
Java – How to convert String to Double in Java ?
Problem Statement You want to convert a string value to double in Java. Solution You can use one of the three approaches to convert a string to double in Java. 1. Assigning the string to the constructor of the Double class 2. Using Double.valueOf 3. Using Double.parseDouble The output of the above program is Abundantcode.com Java Tutorials 76.2 String to double using valueOf 76.2 string…
How to concatenate two arrays in Java?
There are many ways in which one can concatenate two arrays in Java. Below is a sample soucrecode demonstrating one of the techniques to concatenate arrays in Java. How to concatenate two arrays in Java?
Java – How to read a valid Integer number from Console ?
Problem Statement You need to read a valid integer number from the Console in your java program. If the number is invalid , show appropriate message. Solution To read a valid integer from a console program , you can use the Scanner class and pass the System.in as the parameter to its constructor. The scanner class exposes a method called nextInt() which can be used…
Java – How to create BigDecimal from long datatype value ?
Problem Statement You need to create BigDecimal values from long type value in your Java program. Solution Use BigDecimal.valueOf method to create BigDecimal from the long value.