Java String Slice sliceLength(int start, int stop, long step)

Here you can find the source of sliceLength(int start, int stop, long step)

Description

Make step a long in case adding the start, stop and step together overflows an int.

License

Open Source License

Declaration

public static final int sliceLength(int start, int stop, long step) 

Method Source Code

//package com.java2s;

public class Main {
    /**// www .j  a v  a 2  s .  co  m
     * Make step a long in case adding the start, stop and step together overflows an int.
     */
    public static final int sliceLength(int start, int stop, long step) {
        int ret;
        if (step > 0) {
            ret = (int) ((stop - start + step - 1) / step);
        } else {
            ret = (int) ((stop - start + step + 1) / step);
        }

        if (ret < 0) {
            return 0;
        }

        return ret;
    }
}

Related

  1. slice(String contents, int CONTENT_COLUMN_SIZE)
  2. slice(String input, int index, int length)
  3. slice(String line)
  4. slice(String value, int beginOffset, int endOffset, boolean trim)
  5. sliceAndMatch(String fstring, String rstring)