Java List to Int List toIntegers(List values)

Here you can find the source of toIntegers(List values)

Description

to Integers

License

Open Source License

Declaration

public static List<Integer> toIntegers(List<String> values) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Integer> toIntegers(List<String> values) {

        if (values == null) {
            return null;
        }/* w  ww  .  j a  va  2 s .  co m*/

        List<Integer> integerValues = new ArrayList<Integer>(values.size());

        for (int index = 0; index < values.size(); index++) {
            String value = values.get(index);
            Integer integerValue = toInteger(value);
            integerValues.add(integerValue);
        }

        return integerValues;
    }

    public static Integer toInteger(String value) {

        Integer integer = null;
        try {
            integer = Integer.parseInt(value);
        } catch (Exception e) {
            integer = null;
        }

        return integer;
    }

    public static int parseInt(String intString, int defaultValue) {

        int parsedInt = defaultValue;

        try {
            parsedInt = Integer.parseInt(intString);
        } catch (Exception e) {
            parsedInt = defaultValue;
        }

        return parsedInt;
    }
}

Related

  1. toIntegerList(int... array)
  2. toIntegerList(int[] array)
  3. toIntegerList(int[] intArray)
  4. toIntegerList(List strList, boolean failOnException)
  5. toIntegers(final List longs)
  6. toIntList(List list)
  7. toIntList(Set members)
  8. toIntList(String arr, String separator)
  9. toInts(List list)