Java Integer signum() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Integer

Definition

In Java, Integer.signum(i) tells you the sign of an int. It returns -1 if the number is negative, 0 if it is zero, and 1 if it is positive.

The result is always one of those three values, so it works nicely in a switch statement, or as a step direction that moves a number toward a target.

A static method of java.lang.Integer (since Java 1.5): call it on the class, as Integer.signum(...). Integer lives in java.lang, so no import is needed.

Syntax

One argument: the number to examine.

Java
int a = Integer.signum(-42);   // -1
int b = Integer.signum(0);     // 0
int c = Integer.signum(42);    // 1
CallWhat it does
Integer.signum(i)-1, 0, or 1 for negative, zero, or positive.
Integer.signum(a - b)Direction from b to a (careful: subtraction can overflow).
Integer.compare(a, b)The safe way to compare two numbers instead.
i == 0 ? 0 : (i > 0 ? 1 : -1)What signum does, written out by hand.

The result is never anything other than -1, 0, or 1, even for Integer.MIN_VALUE and Integer.MAX_VALUE.

Library declarations
Java
// java.lang.Integer
public static int signum(int i)

Parameters

ParameterDescription
i (int)The number whose sign you want.

Return Value

Return ValueDescription
-1i is negative.
0i is zero.
1i is positive.

Compare with Similar Methods

Related methods:

MethodHow it differs
compare(a, b)Compares two values safely instead of examining one.
max(a, b)Picks the larger value instead of reporting a sign.
compareTo(o)Gives -1, 0, or 1 for two Integer objects.
Collections.reverseOrder()Flips the order of a comparison.

Java Examples

Example 1 — See the Sign of Several Numbers

Print the sign of a negative number, zero, a positive number, and the extremes of int.

Java
public class IntegerSignumDemo {
    public static void main(String[] args) {
        int[] numbers = {-42, -1, 0, 1, 42, Integer.MIN_VALUE, Integer.MAX_VALUE};
        for (int n : numbers) {
            System.out.println("signum(" + n + ") = " + Integer.signum(n));
        }
    }
}

How It Works

  1. Negative gives -1. Both -42 and -1 return -1, whatever their size.
  2. Zero gives 0. Zero is neither negative nor positive, so it has its own answer.
  3. Positive gives 1. Both 1 and 42 return 1.
  4. The extremes too. MIN_VALUE returns -1 and MAX_VALUE returns 1; the size of the number never matters.

Example 2 — Describe Temperatures with a switch

Use the three possible answers of signum as the cases of a switch statement.

Java
public class IntegerSignumSwitch {
    static String describe(int celsius) {
        switch (Integer.signum(celsius)) {
            case -1:
                return celsius + " C: below freezing";
            case 0:
                return celsius + " C: exactly freezing";
            default:
                return celsius + " C: above freezing";
        }
    }

    public static void main(String[] args) {
        int[] readings = {-8, 0, 17};
        for (int reading : readings) {
            System.out.println(describe(reading));
        }
    }
}

How It Works

  1. A switch on three values. Because signum returns only -1, 0, or 1, the switch covers every case.
  2. case -1. Any negative temperature, such as -8, lands here and is below freezing.
  3. case 0. Only 0 itself matches, so it is described as exactly freezing.
  4. The default case. The only value left is 1, so a positive reading like 17 is above freezing.

Example 3 — Walk a Number Toward a Target

Use the sign of the remaining distance as a step, so the same code works in both directions.

Java
public class IntegerSignumStep {
    static void walk(int start, int target) {
        int position = start;
        StringBuilder path = new StringBuilder(String.valueOf(position));

        while (position != target) {
            position += Integer.signum(target - position);
            path.append(" -> ").append(position);
        }
        System.out.println(path);
    }

    public static void main(String[] args) {
        walk(2, -2);
        walk(-1, 3);
        walk(4, 4);
    }
}

How It Works

  1. The sign is the direction. target - position is negative when the target is behind and positive when it is ahead, so signum gives a step of -1 or 1.
  2. Walking down. From 2 to -2, each step adds -1: 2, 1, 0, -1, -2.
  3. Walking up. From -1 to 3, each step adds 1 and the same code works unchanged.
  4. Already there. When start and target are equal, the loop never runs and only the starting number is printed.

Frequently Asked Questions

It returns -1 for a negative int, 0 for zero, and 1 for a positive int.
Call Integer.signum(i), or compare directly with i < 0, i == 0, and i > 0. Both are correct; signum is handy in a switch.
Yes. Integer.MIN_VALUE returns -1 and Integer.MAX_VALUE returns 1.
Not always. The subtraction can overflow for large values. Use Integer.compare(a, b) instead.
Math.signum works on double and float and returns a floating-point result. Integer.signum is only for int.

Next: sum()

Add two int values, as a method you can pass around.

sum() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful