Question #46966

Use Java code to write a function that converts an array of Strings to an array of integers.
Example:
arr = {“40”, ”50“, ”70”}
to arr = {40,50,70}.

Expert's answer

Answer on Question #46966 - Programming, Java | JSP | JSF

1. Use Java code to write a function that converts an array of Strings to an array of integers. Example:

arr = {"40", "50", "70"}

to arr = {40,50,70}.

Solution.


public int[] convertArray(String[] strArr) {
    int[] iArray = new int[strArr.length];
    for(int i = 0; i < strArr.length; i++) {
        iArray[i] = Integer.parseInt(strArr[i]);
    }
    return iArray;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS