• 24 September

    Display Negative Number in Parentheses in Java

    In this post, we will see how to display negative number in Parentheses in Java. We can use pattern #,##0.00;(#,##0.00) with DecimalFormat‘s format() to display negative number in Parenthesis in Java. package org.arpit.java2blog; import java.text.DecimalFormat; public class DisplayNegativeNumbersInParenthesis { public static void main(String[] args) { DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(); String pattern = "#,##0.00;(#,##0.00)"; df.applyPattern(pattern); […]

  • 24 September

    Increment for Loop by 2 in Java

    In this post, we will see how to increment for loop by 2 in Java. There are several looping statements available in Java and one of them is for loop in java. There are three parts of for loop. Initialization Condition Increment or decrement for (initialization; condition; increment/decrement) { //block of statements } Initialization: Initialization […]

  • 24 September

    Get List of Month Names in Java

    In this post, we will see how to get list of months name in Java. Using DateFormatSymbols’s getMonth() method We can use DateFormatSymbols's getMonth() to get list of months in Java. It will provide complete month names like January, February etc. package org.arpit.java2blog; import java.text.DateFormatSymbols; import java.util.Arrays; public class GetListOfMonths { public static void main(String[] […]

  • 21 September

    Convert 0 and 1 to boolean in Java

    In this post, we will see how to convert 0 and 1 to Boolean in Java. Given “0” and “1” in String datatype, convert it to boolean datatype where “0” represents false “1” represents true Convert 0 and 1 to Boolean in Java Here is program to convert 0 and 1 to boolean in Java […]

  • 20 September

    Replace Backslash with Forward Slash in Java

    1. Introduction In this post, we will learn about how to replace backslash with forward slash in java. backslash() is used as escape character in Java. For example: It can be used to: Used in special characters such as new line character \n, tab \t Write unicode characters like \u%04x. That’s the reason we can’t […]

  • 20 September

    Remove Backslash from String in Java

    Learn about how to remove backslash from String in Java. backslash() is used as escape character in Java. For example it can be used to: Create special characters such as new line character \n, tab \t Write unicode characters like \u%04x. Ways to Remove Backslash from String in Java 1. Using replace() Method Use String’s […]

  • 20 September

    Convert 0 to 1 and 1 to 0 in Java

    In this post, we wil see how to convert 0 to 1 and 1 to 0 in java. There are lots of ways to convert 0 to 1 and 1 to 0 in Java. Let’s go through them. Using Subtraction This is one of easiest solution to swap 0 to 1 and vice versa. Just […]

  • 20 September

    Get Unix Timestamp in Java

    In this post, we will get unix timestamp in Java. As per wikipedia Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970. Unix time is standard way […]

  • 20 September

    Return ArrayList in Java

    This article discusses cases of returning an ArrayList in Java from a method. An ArrayList in Java is a collection of elements of the same data type under a single variable name. In different cases, you can return an ArrayList from a method in Java. These cases are as given below. Returning ArrayList from a […]

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.