Java Regex Int Validate parseInt(String[] strs)

Here you can find the source of parseInt(String[] strs)

Description

parse Int

License

Open Source License

Declaration

public static int[] parseInt(String[] strs) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.regex.Pattern;

public class Main {

    public static int[] parseInt(String[] strs) {
        int[] strs_int = new int[strs.length];
        for (int i = 0; i < strs_int.length; i++) {
            if (can2Int(strs[i])) {
                strs_int[i] = Integer.parseInt(strs[i]);
            }//from w  w w.  j a va  2  s. c o m
        }
        return strs_int;
    }

    public static int[] parseInt(long[] longs) {
        int[] strs_int = new int[longs.length];
        for (int i = 0; i < strs_int.length; i++) {
            if (can2Int(longs[i])) {
                strs_int[i] = (int) longs[i];
            }
        }
        return strs_int;
    }

    public static boolean can2Int(String str) {
        if (str == null || "".equals(str))
            return false;
        if (str.startsWith("-")) {
            String str2 = str.substring(1, str.length());
            return Pattern.matches("[0]||[1-9][0-9]{0,9}", str2)
                    && Long.parseLong(str2) < Long.parseLong("2147483649");
        } else
            return Pattern.matches("[0]||[1-9][0-9]{0,9}", str)
                    && Long.parseLong(str) < Long.parseLong("2147483648");
    }

    public static boolean can2Int(long lon) {
        return lon < 2147483647 && lon > -2147483648;
    }

    public static long[] parseLong(int[] ints) {
        long[] longs = new long[ints.length];
        for (int i = 0; i < longs.length; i++) {
            longs[i] = (long) ints[i];
        }
        return longs;
    }
}

Related

  1. parseInt(Object str)
  2. parseInt(String value)
  3. parseInteger(String attrVal)
  4. parseInteger(String inStr, Integer def)
  5. parseInteger(String key, String sourceString)
  6. parseInteger(String str)