Java Utililty Methods Integer Divide

List of utility methods to do Integer Divide

Description

The list of methods to do Integer Divide are organized into topic(s).

Method

intdivideAndCeil(int a, int b)
divide And Ceil
if (b == 0) {
    return 0;
return (a + (b - 1)) / b;
intdivideAndCeil(int dividend, int divisor)
divide And Ceil
return (dividend + divisor - 1) / divisor;
intdivideAndRound(int dividend, int divisor)
Perform a division of the input integers, and round to the next integer if the divisor is not a even multiple of the dividend.
int result = 0;
if (divisor != 0) {
    result = ((dividend % divisor) == 0) ? (dividend / divisor) : ((dividend / divisor) + 1);
return result;
intdivideAndRoundUp(long dividend, int divisor)
divide And Round Up
if ((dividend % (long) divisor) == 0)
    return (int) (dividend / (long) divisor);
return (int) (dividend / (long) divisor + 1);
intdivideRoundUp(int first, int second)
divide Round Up
return (int) Math.ceil((double) first / (double) second);
StringdivideStringWithInt(String strDividend, int divisor)
divide String With Int
return Integer.toString(Integer.parseInt(strDividend) / divisor);
intdivideToCeil(int numerator, int denominator)
Performs a division and rounds upwards to the next integer.
Double result = Math.ceil((double) numerator / denominator);
return result.intValue();
int[]divideToInt(String address)
divide To Int
String[] tab = address.split("\\.");
int[] finalTab = new int[tab.length];
for (int i = 0; i < 4; i++) {
    finalTab[i] = Integer.parseInt(tab[i]);
return finalTab;
intdivideUnsigned(int dividend, int divisor)
Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.
if (divisor >= 0) {
    if (dividend >= 0) {
        return dividend / divisor;
    int q = ((dividend >>> 1) / divisor) << 1;
    dividend -= q * divisor;
    if (dividend < 0L || dividend >= divisor) {
        q++;
...
intdivideWithCeilingRoundingMode(int p, int q)
divide With Ceiling Rounding Mode
if (q == 0) {
    throw new ArithmeticException("/ by zero"); 
int div = p / q;
int rem = p - q * div; 
if (rem == 0) {
    return div;
int signum = 1 | ((p ^ q) >> (Integer.SIZE - 1));
boolean increment = signum > 0;
return increment ? div + signum : div;