Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int n, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) n / nums;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_alt(String nums) {
        if (nums == null) {
            return 0;
        }
        int count = 0;
        for (char c : nums.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe(String str) {
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + str);
            return 0;
        }
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_new(int[] str) {
        if (str == null || str.length == 0) {
            throw new IllegalArgumentException("str must not be null or empty");
        }
        int max = str[0];
        for (int v : str) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeHelper(String arr) {
        try {
            return Integer.parseInt(arr);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + arr);
            return 0;
        }
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_alt(int[] list) {
        if (list == null || list.length == 0) {
            throw new IllegalArgumentException("list must not be null or empty");
        }
        int max = list[0];
        for (int v : list) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int value, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) value / nums;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int str, int input) {
        if (input == 0) {
            throw new IllegalArgumentException("input must not be zero");
        }
        return (double) str / input;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> list, List<Integer> s) {
        if (list == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(list.size() + s.size());
        int i = 0, j = 0;
        while (i < list.size() && j < s.size()) {
            if (list.get(i) <= s.get(j)) {
                text.add(list.get(i++));
            } else {
                text.add(s.get(j++));
            }
        }
        while (i < list.size()) {
            text.add(list.get(i++));
        }
        while (j < s.size()) {
            text.add(s.get(j++));
        }
        return text;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int input, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) input / n;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_v2(int[] str) {
        if (str == null || str.length == 0) {
            throw new IllegalArgumentException("str must not be null or empty");
        }
        int max = str[0];
        for (int v : str) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowelsHelper(String n) {
        if (n == null) {
            return 0;
        }
        int count = 0;
        for (char c : n.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int nums, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) nums / list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> nums, List<Integer> value) {
        if (nums == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(nums.size() + value.size());
        int i = 0, j = 0;
        while (i < nums.size() && j < value.size()) {
            if (nums.get(i) <= value.get(j)) {
                s.add(nums.get(i++));
            } else {
                s.add(value.get(j++));
            }
        }
        while (i < nums.size()) {
            s.add(nums.get(i++));
        }
        while (j < value.size()) {
            s.add(value.get(j++));
        }
        return s;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_alt(String str) {
        if (str == null) {
            return null;
        }
        return new StringBuilder(str).reverse().toString();
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringEx(String list) {
        if (list == null) {
            return null;
        }
        return new StringBuilder(list).reverse().toString();
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_new(String value) {
        if (value == null) {
            return null;
        }
        return new StringBuilder(value).reverse().toString();
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_alt(String input) {
        try {
            return Integer.parseInt(input);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + input);
            return 0;
        }
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int value, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) value / n;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_new(String text) {
        try {
            return Integer.parseInt(text);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + text);
            return 0;
        }
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int arr, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) arr / list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> input, List<Integer> s) {
        if (input == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(input.size() + s.size());
        int i = 0, j = 0;
        while (i < input.size() && j < s.size()) {
            if (input.get(i) <= s.get(j)) {
                text.add(input.get(i++));
            } else {
                text.add(s.get(j++));
            }
        }
        while (i < input.size()) {
            text.add(input.get(i++));
        }
        while (j < s.size()) {
            text.add(s.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrime_v2(int arr) {
        if (arr < 2) {
            return false;
        }
        for (int i = 2; i * i <= arr; i++) {
            if (arr % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideHelper(int text, int value) {
        if (value == 0) {
            throw new IllegalArgumentException("value must not be zero");
        }
        return (double) text / value;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_alt(String value) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + value);
            return 0;
        }
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_alt(String s) {
        if (s == null) {
            return 0;
        }
        int count = 0;
        for (char c : s.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_new(String input) {
        try {
            return Integer.parseInt(input);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + input);
            return 0;
        }
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> n, List<Integer> value) {
        if (n == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(n.size() + value.size());
        int i = 0, j = 0;
        while (i < n.size() && j < value.size()) {
            if (n.get(i) <= value.get(j)) {
                value.add(n.get(i++));
            } else {
                value.add(value.get(j++));
            }
        }
        while (i < n.size()) {
            value.add(n.get(i++));
        }
        while (j < value.size()) {
            value.add(value.get(j++));
        }
        return value;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_v2(String str) {
        if (str == null) {
            return 0;
        }
        int count = 0;
        for (char c : str.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> arr, List<Integer> s) {
        if (arr == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> input = new ArrayList<>(arr.size() + s.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < s.size()) {
            if (arr.get(i) <= s.get(j)) {
                input.add(arr.get(i++));
            } else {
                input.add(s.get(j++));
            }
        }
        while (i < arr.size()) {
            input.add(arr.get(i++));
        }
        while (j < s.size()) {
            input.add(s.get(j++));
        }
        return input;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> arr, List<Integer> s) {
        if (arr == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(arr.size() + s.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < s.size()) {
            if (arr.get(i) <= s.get(j)) {
                value.add(arr.get(i++));
            } else {
                value.add(s.get(j++));
            }
        }
        while (i < arr.size()) {
            value.add(arr.get(i++));
        }
        while (j < s.size()) {
            value.add(s.get(j++));
        }
        return value;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeHelper(int arr) {
        if (arr < 2) {
            return false;
        }
        for (int i = 2; i * i <= arr; i++) {
            if (arr % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString(String text) {
        if (text == null) {
            return null;
        }
        return new StringBuilder(text).reverse().toString();
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> value) {
        if (s == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(s.size() + value.size());
        int i = 0, j = 0;
        while (i < s.size() && j < value.size()) {
            if (s.get(i) <= value.get(j)) {
                n.add(s.get(i++));
            } else {
                n.add(value.get(j++));
            }
        }
        while (i < s.size()) {
            n.add(s.get(i++));
        }
        while (j < value.size()) {
            n.add(value.get(j++));
        }
        return n;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int maxHelper(int[] nums) {
        if (nums == null || nums.length == 0) {
            throw new IllegalArgumentException("nums must not be null or empty");
        }
        int max = nums[0];
        for (int v : nums) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> text, List<Integer> input) {
        if (text == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(text.size() + input.size());
        int i = 0, j = 0;
        while (i < text.size() && j < input.size()) {
            if (text.get(i) <= input.get(j)) {
                text.add(text.get(i++));
            } else {
                text.add(input.get(j++));
            }
        }
        while (i < text.size()) {
            text.add(text.get(i++));
        }
        while (j < input.size()) {
            text.add(input.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_new(String arr) {
        if (arr == null) {
            return null;
        }
        return new StringBuilder(arr).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int value, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) value / n;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels(String list) {
        if (list == null) {
            return 0;
        }
        int count = 0;
        for (char c : list.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> list, List<Integer> list) {
        if (list == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(list.size() + list.size());
        int i = 0, j = 0;
        while (i < list.size() && j < list.size()) {
            if (list.get(i) <= list.get(j)) {
                nums.add(list.get(i++));
            } else {
                nums.add(list.get(j++));
            }
        }
        while (i < list.size()) {
            nums.add(list.get(i++));
        }
        while (j < list.size()) {
            nums.add(list.get(j++));
        }
        return nums;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> nums) {
        if (text == null || nums == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(text.size() + nums.size());
        int i = 0, j = 0;
        while (i < text.size() && j < nums.size()) {
            if (text.get(i) <= nums.get(j)) {
                n.add(text.get(i++));
            } else {
                n.add(nums.get(j++));
            }
        }
        while (i < text.size()) {
            n.add(text.get(i++));
        }
        while (j < nums.size()) {
            n.add(nums.get(j++));
        }
        return n;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int nums, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) nums / nums;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_alt(String list) {
        if (list == null) {
            return 0;
        }
        int count = 0;
        for (char c : list.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> list, List<Integer> text) {
        if (list == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(list.size() + text.size());
        int i = 0, j = 0;
        while (i < list.size() && j < text.size()) {
            if (list.get(i) <= text.get(j)) {
                list.add(list.get(i++));
            } else {
                list.add(text.get(j++));
            }
        }
        while (i < list.size()) {
            list.add(list.get(i++));
        }
        while (j < text.size()) {
            list.add(text.get(j++));
        }
        return list;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int n, int input) {
        if (input == 0) {
            throw new IllegalArgumentException("input must not be zero");
        }
        return (double) n / input;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowelsEx(String str) {
        if (str == null) {
            return 0;
        }
        int count = 0;
        for (char c : str.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int list, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) list / list;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_alt(String str) {
        if (str == null) {
            return 0;
        }
        int count = 0;
        for (char c : str.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> str, List<Integer> s) {
        if (str == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(str.size() + s.size());
        int i = 0, j = 0;
        while (i < str.size() && j < s.size()) {
            if (str.get(i) <= s.get(j)) {
                value.add(str.get(i++));
            } else {
                value.add(s.get(j++));
            }
        }
        while (i < str.size()) {
            value.add(str.get(i++));
        }
        while (j < s.size()) {
            value.add(s.get(j++));
        }
        return value;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_v2(String value) {
        if (value == null) {
            return 0;
        }
        int count = 0;
        for (char c : value.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int text, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) text / nums;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> input) {
        if (text == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(text.size() + input.size());
        int i = 0, j = 0;
        while (i < text.size() && j < input.size()) {
            if (text.get(i) <= input.get(j)) {
                text.add(text.get(i++));
            } else {
                text.add(input.get(j++));
            }
        }
        while (i < text.size()) {
            text.add(text.get(i++));
        }
        while (j < input.size()) {
            text.add(input.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> nums, List<Integer> str) {
        if (nums == null || str == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> arr = new ArrayList<>(nums.size() + str.size());
        int i = 0, j = 0;
        while (i < nums.size() && j < str.size()) {
            if (nums.get(i) <= str.get(j)) {
                arr.add(nums.get(i++));
            } else {
                arr.add(str.get(j++));
            }
        }
        while (i < nums.size()) {
            arr.add(nums.get(i++));
        }
        while (j < str.size()) {
            arr.add(str.get(j++));
        }
        return arr;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_alt(String s) {
        if (s == null) {
            return null;
        }
        return new StringBuilder(s).reverse().toString();
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels(String nums) {
        if (nums == null) {
            return 0;
        }
        int count = 0;
        for (char c : nums.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int list, int str) {
        if (str == 0) {
            throw new IllegalArgumentException("str must not be zero");
        }
        return (double) list / str;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringHelper(String n) {
        if (n == null) {
            return null;
        }
        return new StringBuilder(n).reverse().toString();
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeEx(int text) {
        if (text < 2) {
            return false;
        }
        for (int i = 2; i * i <= text; i++) {
            if (text % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> text, List<Integer> str) {
        if (text == null || str == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(text.size() + str.size());
        int i = 0, j = 0;
        while (i < text.size() && j < str.size()) {
            if (text.get(i) <= str.get(j)) {
                value.add(text.get(i++));
            } else {
                value.add(str.get(j++));
            }
        }
        while (i < text.size()) {
            value.add(text.get(i++));
        }
        while (j < str.size()) {
            value.add(str.get(j++));
        }
        return value;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedEx(List<Integer> s, List<Integer> value) {
        if (s == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(s.size() + value.size());
        int i = 0, j = 0;
        while (i < s.size() && j < value.size()) {
            if (s.get(i) <= value.get(j)) {
                text.add(s.get(i++));
            } else {
                text.add(value.get(j++));
            }
        }
        while (i < s.size()) {
            text.add(s.get(i++));
        }
        while (j < value.size()) {
            text.add(value.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> n, List<Integer> n) {
        if (n == null || n == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(n.size() + n.size());
        int i = 0, j = 0;
        while (i < n.size() && j < n.size()) {
            if (n.get(i) <= n.get(j)) {
                value.add(n.get(i++));
            } else {
                value.add(n.get(j++));
            }
        }
        while (i < n.size()) {
            value.add(n.get(i++));
        }
        while (j < n.size()) {
            value.add(n.get(j++));
        }
        return value;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int list, int input) {
        if (input == 0) {
            throw new IllegalArgumentException("input must not be zero");
        }
        return (double) list / input;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> value, List<Integer> input) {
        if (value == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(value.size() + input.size());
        int i = 0, j = 0;
        while (i < value.size() && j < input.size()) {
            if (value.get(i) <= input.get(j)) {
                s.add(value.get(i++));
            } else {
                s.add(input.get(j++));
            }
        }
        while (i < value.size()) {
            s.add(value.get(i++));
        }
        while (j < input.size()) {
            s.add(input.get(j++));
        }
        return s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_new(List<Integer> input, List<Integer> nums) {
        if (input == null || nums == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> arr = new ArrayList<>(input.size() + nums.size());
        int i = 0, j = 0;
        while (i < input.size() && j < nums.size()) {
            if (input.get(i) <= nums.get(j)) {
                arr.add(input.get(i++));
            } else {
                arr.add(nums.get(j++));
            }
        }
        while (i < input.size()) {
            arr.add(input.get(i++));
        }
        while (j < nums.size()) {
            arr.add(nums.get(j++));
        }
        return arr;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrime_v2(int text) {
        if (text < 2) {
            return false;
        }
        for (int i = 2; i * i <= text; i++) {
            if (text % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int list, int str) {
        if (str == 0) {
            throw new IllegalArgumentException("str must not be zero");
        }
        return (double) list / str;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int s, int text) {
        if (text == 0) {
            throw new IllegalArgumentException("text must not be zero");
        }
        return (double) s / text;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_v2(String input) {
        if (input == null) {
            return 0;
        }
        int count = 0;
        for (char c : input.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int arr, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) arr / nums;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedEx(List<Integer> s, List<Integer> s) {
        if (s == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(s.size() + s.size());
        int i = 0, j = 0;
        while (i < s.size() && j < s.size()) {
            if (s.get(i) <= s.get(j)) {
                text.add(s.get(i++));
            } else {
                text.add(s.get(j++));
            }
        }
        while (i < s.size()) {
            text.add(s.get(i++));
        }
        while (j < s.size()) {
            text.add(s.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_v2(String arr) {
        if (arr == null) {
            return 0;
        }
        int count = 0;
        for (char c : arr.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_v2(int[] nums) {
        if (nums == null || nums.length == 0) {
            throw new IllegalArgumentException("nums must not be null or empty");
        }
        int max = nums[0];
        for (int v : nums) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrime(int text) {
        if (text < 2) {
            return false;
        }
        for (int i = 2; i * i <= text; i++) {
            if (text % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> text, List<Integer> list) {
        if (text == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> arr = new ArrayList<>(text.size() + list.size());
        int i = 0, j = 0;
        while (i < text.size() && j < list.size()) {
            if (text.get(i) <= list.get(j)) {
                arr.add(text.get(i++));
            } else {
                arr.add(list.get(j++));
            }
        }
        while (i < text.size()) {
            arr.add(text.get(i++));
        }
        while (j < list.size()) {
            arr.add(list.get(j++));
        }
        return arr;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeHelper(String value) {
        try {
            return Integer.parseInt(value);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + value);
            return 0;
        }
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> input, List<Integer> nums) {
        if (input == null || nums == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(input.size() + nums.size());
        int i = 0, j = 0;
        while (i < input.size() && j < nums.size()) {
            if (input.get(i) <= nums.get(j)) {
                nums.add(input.get(i++));
            } else {
                nums.add(nums.get(j++));
            }
        }
        while (i < input.size()) {
            nums.add(input.get(i++));
        }
        while (j < nums.size()) {
            nums.add(nums.get(j++));
        }
        return nums;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int value, int nums) {
        if (nums == 0) {
            throw new IllegalArgumentException("nums must not be zero");
        }
        return (double) value / nums;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_alt(String text) {
        if (text == null) {
            return null;
        }
        return new StringBuilder(text).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int text, int value) {
        if (value == 0) {
            throw new IllegalArgumentException("value must not be zero");
        }
        return (double) text / value;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_v2(int[] list) {
        if (list == null || list.length == 0) {
            throw new IllegalArgumentException("list must not be null or empty");
        }
        int max = list[0];
        for (int v : list) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> arr, List<Integer> text) {
        if (arr == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(arr.size() + text.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < text.size()) {
            if (arr.get(i) <= text.get(j)) {
                text.add(arr.get(i++));
            } else {
                text.add(text.get(j++));
            }
        }
        while (i < arr.size()) {
            text.add(arr.get(i++));
        }
        while (j < text.size()) {
            text.add(text.get(j++));
        }
        return text;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_alt(int[] input) {
        if (input == null || input.length == 0) {
            throw new IllegalArgumentException("input must not be null or empty");
        }
        int max = input[0];
        for (int v : input) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> input) {
        if (s == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(s.size() + input.size());
        int i = 0, j = 0;
        while (i < s.size() && j < input.size()) {
            if (s.get(i) <= input.get(j)) {
                nums.add(s.get(i++));
            } else {
                nums.add(input.get(j++));
            }
        }
        while (i < s.size()) {
            nums.add(s.get(i++));
        }
        while (j < input.size()) {
            nums.add(input.get(j++));
        }
        return nums;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringHelper(String list) {
        if (list == null) {
            return null;
        }
        return new StringBuilder(list).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int s, int arr) {
        if (arr == 0) {
            throw new IllegalArgumentException("arr must not be zero");
        }
        return (double) s / arr;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int value, int arr) {
        if (arr == 0) {
            throw new IllegalArgumentException("arr must not be zero");
        }
        return (double) value / arr;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe(String nums) {
        try {
            return Integer.parseInt(nums);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + nums);
            return 0;
        }
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_alt(String value) {
        if (value == null) {
            return 0;
        }
        int count = 0;
        for (char c : value.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> value, List<Integer> str) {
        if (value == null || str == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(value.size() + str.size());
        int i = 0, j = 0;
        while (i < value.size() && j < str.size()) {
            if (value.get(i) <= str.get(j)) {
                value.add(value.get(i++));
            } else {
                value.add(str.get(j++));
            }
        }
        while (i < value.size()) {
            value.add(value.get(i++));
        }
        while (j < str.size()) {
            value.add(str.get(j++));
        }
        return value;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> arr, List<Integer> list) {
        if (arr == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(arr.size() + list.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < list.size()) {
            if (arr.get(i) <= list.get(j)) {
                s.add(arr.get(i++));
            } else {
                s.add(list.get(j++));
            }
        }
        while (i < arr.size()) {
            s.add(arr.get(i++));
        }
        while (j < list.size()) {
            s.add(list.get(j++));
        }
        return s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> text) {
        if (s == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(s.size() + text.size());
        int i = 0, j = 0;
        while (i < s.size() && j < text.size()) {
            if (s.get(i) <= text.get(j)) {
                n.add(s.get(i++));
            } else {
                n.add(text.get(j++));
            }
        }
        while (i < s.size()) {
            n.add(s.get(i++));
        }
        while (j < text.size()) {
            n.add(text.get(j++));
        }
        return n;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_alt(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new IllegalArgumentException("arr must not be null or empty");
        }
        int max = arr[0];
        for (int v : arr) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeEx(String s) {
        try {
            return Integer.parseInt(s);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + s);
            return 0;
        }
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int value, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) value / s;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrime_alt(int str) {
        if (str < 2) {
            return false;
        }
        for (int i = 2; i * i <= str; i++) {
            if (str % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> str, List<Integer> n) {
        if (str == null || n == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(str.size() + n.size());
        int i = 0, j = 0;
        while (i < str.size() && j < n.size()) {
            if (str.get(i) <= n.get(j)) {
                value.add(str.get(i++));
            } else {
                value.add(n.get(j++));
            }
        }
        while (i < str.size()) {
            value.add(str.get(i++));
        }
        while (j < n.size()) {
            value.add(n.get(j++));
        }
        return value;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int arr, int input) {
        if (input == 0) {
            throw new IllegalArgumentException("input must not be zero");
        }
        return (double) arr / input;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_v2(int[] s) {
        if (s == null || s.length == 0) {
            throw new IllegalArgumentException("s must not be null or empty");
        }
        int max = s[0];
        for (int v : s) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> input, List<Integer> s) {
        if (input == null || s == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(input.size() + s.size());
        int i = 0, j = 0;
        while (i < input.size() && j < s.size()) {
            if (input.get(i) <= s.get(j)) {
                n.add(input.get(i++));
            } else {
                n.add(s.get(j++));
            }
        }
        while (i < input.size()) {
            n.add(input.get(i++));
        }
        while (j < s.size()) {
            n.add(s.get(j++));
        }
        return n;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels(String n) {
        if (n == null) {
            return 0;
        }
        int count = 0;
        for (char c : n.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> nums, List<Integer> list) {
        if (nums == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(nums.size() + list.size());
        int i = 0, j = 0;
        while (i < nums.size() && j < list.size()) {
            if (nums.get(i) <= list.get(j)) {
                list.add(nums.get(i++));
            } else {
                list.add(list.get(j++));
            }
        }
        while (i < nums.size()) {
            list.add(nums.get(i++));
        }
        while (j < list.size()) {
            list.add(list.get(j++));
        }
        return list;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_v2(String str) {
        if (str == null) {
            return null;
        }
        return new StringBuilder(str).reverse().toString();
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_new(String text) {
        if (text == null) {
            return null;
        }
        return new StringBuilder(text).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideHelper(int arr, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) arr / n;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeHelper(int input) {
        if (input < 2) {
            return false;
        }
        for (int i = 2; i * i <= input; i++) {
            if (input % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_new(String s) {
        if (s == null) {
            return null;
        }
        return new StringBuilder(s).reverse().toString();
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedEx(List<Integer> nums, List<Integer> nums) {
        if (nums == null || nums == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(nums.size() + nums.size());
        int i = 0, j = 0;
        while (i < nums.size() && j < nums.size()) {
            if (nums.get(i) <= nums.get(j)) {
                n.add(nums.get(i++));
            } else {
                n.add(nums.get(j++));
            }
        }
        while (i < nums.size()) {
            n.add(nums.get(i++));
        }
        while (j < nums.size()) {
            n.add(nums.get(j++));
        }
        return n;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeEx(String arr) {
        try {
            return Integer.parseInt(arr);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + arr);
            return 0;
        }
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringHelper(String s) {
        if (s == null) {
            return null;
        }
        return new StringBuilder(s).reverse().toString();
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowelsEx(String text) {
        if (text == null) {
            return 0;
        }
        int count = 0;
        for (char c : text.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int value, int str) {
        if (str == 0) {
            throw new IllegalArgumentException("str must not be zero");
        }
        return (double) value / str;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max(int[] str) {
        if (str == null || str.length == 0) {
            throw new IllegalArgumentException("str must not be null or empty");
        }
        int max = str[0];
        for (int v : str) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_alt(int[] nums) {
        if (nums == null || nums.length == 0) {
            throw new IllegalArgumentException("nums must not be null or empty");
        }
        int max = nums[0];
        for (int v : nums) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedEx(List<Integer> arr, List<Integer> value) {
        if (arr == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> str = new ArrayList<>(arr.size() + value.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < value.size()) {
            if (arr.get(i) <= value.get(j)) {
                str.add(arr.get(i++));
            } else {
                str.add(value.get(j++));
            }
        }
        while (i < arr.size()) {
            str.add(arr.get(i++));
        }
        while (j < value.size()) {
            str.add(value.get(j++));
        }
        return str;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> n, List<Integer> input) {
        if (n == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(n.size() + input.size());
        int i = 0, j = 0;
        while (i < n.size() && j < input.size()) {
            if (n.get(i) <= input.get(j)) {
                list.add(n.get(i++));
            } else {
                list.add(input.get(j++));
            }
        }
        while (i < n.size()) {
            list.add(n.get(i++));
        }
        while (j < input.size()) {
            list.add(input.get(j++));
        }
        return list;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int value, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) value / s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedEx(List<Integer> list, List<Integer> input) {
        if (list == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(list.size() + input.size());
        int i = 0, j = 0;
        while (i < list.size() && j < input.size()) {
            if (list.get(i) <= input.get(j)) {
                s.add(list.get(i++));
            } else {
                s.add(input.get(j++));
            }
        }
        while (i < list.size()) {
            s.add(list.get(i++));
        }
        while (j < input.size()) {
            s.add(input.get(j++));
        }
        return s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> arr, List<Integer> text) {
        if (arr == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(arr.size() + text.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < text.size()) {
            if (arr.get(i) <= text.get(j)) {
                list.add(arr.get(i++));
            } else {
                list.add(text.get(j++));
            }
        }
        while (i < arr.size()) {
            list.add(arr.get(i++));
        }
        while (j < text.size()) {
            list.add(text.get(j++));
        }
        return list;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int input, int text) {
        if (text == 0) {
            throw new IllegalArgumentException("text must not be zero");
        }
        return (double) input / text;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_v2(String list) {
        if (list == null) {
            return null;
        }
        return new StringBuilder(list).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideHelper(int str, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) str / s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> s, List<Integer> input) {
        if (s == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> input = new ArrayList<>(s.size() + input.size());
        int i = 0, j = 0;
        while (i < s.size() && j < input.size()) {
            if (s.get(i) <= input.get(j)) {
                input.add(s.get(i++));
            } else {
                input.add(input.get(j++));
            }
        }
        while (i < s.size()) {
            input.add(s.get(i++));
        }
        while (j < input.size()) {
            input.add(input.get(j++));
        }
        return input;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideHelper(int arr, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) arr / s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> n, List<Integer> list) {
        if (n == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> str = new ArrayList<>(n.size() + list.size());
        int i = 0, j = 0;
        while (i < n.size() && j < list.size()) {
            if (n.get(i) <= list.get(j)) {
                str.add(n.get(i++));
            } else {
                str.add(list.get(j++));
            }
        }
        while (i < n.size()) {
            str.add(n.get(i++));
        }
        while (j < list.size()) {
            str.add(list.get(j++));
        }
        return str;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int s, int arr) {
        if (arr == 0) {
            throw new IllegalArgumentException("arr must not be zero");
        }
        return (double) s / arr;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> value, List<Integer> list) {
        if (value == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(value.size() + list.size());
        int i = 0, j = 0;
        while (i < value.size() && j < list.size()) {
            if (value.get(i) <= list.get(j)) {
                nums.add(value.get(i++));
            } else {
                nums.add(list.get(j++));
            }
        }
        while (i < value.size()) {
            nums.add(value.get(i++));
        }
        while (j < list.size()) {
            nums.add(list.get(j++));
        }
        return nums;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_new(List<Integer> nums, List<Integer> value) {
        if (nums == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(nums.size() + value.size());
        int i = 0, j = 0;
        while (i < nums.size() && j < value.size()) {
            if (nums.get(i) <= value.get(j)) {
                list.add(nums.get(i++));
            } else {
                list.add(value.get(j++));
            }
        }
        while (i < nums.size()) {
            list.add(nums.get(i++));
        }
        while (j < value.size()) {
            list.add(value.get(j++));
        }
        return list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> input, List<Integer> input) {
        if (input == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(input.size() + input.size());
        int i = 0, j = 0;
        while (i < input.size() && j < input.size()) {
            if (input.get(i) <= input.get(j)) {
                list.add(input.get(i++));
            } else {
                list.add(input.get(j++));
            }
        }
        while (i < input.size()) {
            list.add(input.get(i++));
        }
        while (j < input.size()) {
            list.add(input.get(j++));
        }
        return list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> s, List<Integer> list) {
        if (s == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> arr = new ArrayList<>(s.size() + list.size());
        int i = 0, j = 0;
        while (i < s.size() && j < list.size()) {
            if (s.get(i) <= list.get(j)) {
                arr.add(s.get(i++));
            } else {
                arr.add(list.get(j++));
            }
        }
        while (i < s.size()) {
            arr.add(s.get(i++));
        }
        while (j < list.size()) {
            arr.add(list.get(j++));
        }
        return arr;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> value, List<Integer> str) {
        if (value == null || str == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(value.size() + str.size());
        int i = 0, j = 0;
        while (i < value.size() && j < str.size()) {
            if (value.get(i) <= str.get(j)) {
                s.add(value.get(i++));
            } else {
                s.add(str.get(j++));
            }
        }
        while (i < value.size()) {
            s.add(value.get(i++));
        }
        while (j < str.size()) {
            s.add(str.get(j++));
        }
        return s;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int maxEx(int[] value) {
        if (value == null || value.length == 0) {
            throw new IllegalArgumentException("value must not be null or empty");
        }
        int max = value[0];
        for (int v : value) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int text, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) text / list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_new(List<Integer> s, List<Integer> list) {
        if (s == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(s.size() + list.size());
        int i = 0, j = 0;
        while (i < s.size() && j < list.size()) {
            if (s.get(i) <= list.get(j)) {
                n.add(s.get(i++));
            } else {
                n.add(list.get(j++));
            }
        }
        while (i < s.size()) {
            n.add(s.get(i++));
        }
        while (j < list.size()) {
            n.add(list.get(j++));
        }
        return n;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringHelper(String arr) {
        if (arr == null) {
            return null;
        }
        return new StringBuilder(arr).reverse().toString();
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int input, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) input / list;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> text, List<Integer> value) {
        if (text == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> input = new ArrayList<>(text.size() + value.size());
        int i = 0, j = 0;
        while (i < text.size() && j < value.size()) {
            if (text.get(i) <= value.get(j)) {
                input.add(text.get(i++));
            } else {
                input.add(value.get(j++));
            }
        }
        while (i < text.size()) {
            input.add(text.get(i++));
        }
        while (j < value.size()) {
            input.add(value.get(j++));
        }
        return input;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeEx(String list) {
        try {
            return Integer.parseInt(list);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + list);
            return 0;
        }
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int arr, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) arr / n;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_v2(String s) {
        if (s == null) {
            return 0;
        }
        int count = 0;
        for (char c : s.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_alt(List<Integer> text, List<Integer> n) {
        if (text == null || n == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> s = new ArrayList<>(text.size() + n.size());
        int i = 0, j = 0;
        while (i < text.size() && j < n.size()) {
            if (text.get(i) <= n.get(j)) {
                s.add(text.get(i++));
            } else {
                s.add(n.get(j++));
            }
        }
        while (i < text.size()) {
            s.add(text.get(i++));
        }
        while (j < n.size()) {
            s.add(n.get(j++));
        }
        return s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> s, List<Integer> str) {
        if (s == null || str == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(s.size() + str.size());
        int i = 0, j = 0;
        while (i < s.size() && j < str.size()) {
            if (s.get(i) <= str.get(j)) {
                n.add(s.get(i++));
            } else {
                n.add(str.get(j++));
            }
        }
        while (i < s.size()) {
            n.add(s.get(i++));
        }
        while (j < str.size()) {
            n.add(str.get(j++));
        }
        return n;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe(String input) {
        try {
            return Integer.parseInt(input);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + input);
            return 0;
        }
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_new(List<Integer> value, List<Integer> text) {
        if (value == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(value.size() + text.size());
        int i = 0, j = 0;
        while (i < value.size() && j < text.size()) {
            if (value.get(i) <= text.get(j)) {
                nums.add(value.get(i++));
            } else {
                nums.add(text.get(j++));
            }
        }
        while (i < value.size()) {
            nums.add(value.get(i++));
        }
        while (j < text.size()) {
            nums.add(text.get(j++));
        }
        return nums;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowelsHelper(String str) {
        if (str == null) {
            return 0;
        }
        int count = 0;
        for (char c : str.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeEx(int n) {
        if (n < 2) {
            return false;
        }
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> str, List<Integer> list) {
        if (str == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> n = new ArrayList<>(str.size() + list.size());
        int i = 0, j = 0;
        while (i < str.size() && j < list.size()) {
            if (str.get(i) <= list.get(j)) {
                n.add(str.get(i++));
            } else {
                n.add(list.get(j++));
            }
        }
        while (i < str.size()) {
            n.add(str.get(i++));
        }
        while (j < list.size()) {
            n.add(list.get(j++));
        }
        return n;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int maxHelper(int[] input) {
        if (input == null || input.length == 0) {
            throw new IllegalArgumentException("input must not be null or empty");
        }
        int max = input[0];
        for (int v : input) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_new(int n, int text) {
        if (text == 0) {
            throw new IllegalArgumentException("text must not be zero");
        }
        return (double) n / text;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int text, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) text / s;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_new(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new IllegalArgumentException("arr must not be null or empty");
        }
        int max = arr[0];
        for (int v : arr) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int maxHelper(int[] list) {
        if (list == null || list.length == 0) {
            throw new IllegalArgumentException("list must not be null or empty");
        }
        int max = list[0];
        for (int v : list) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> s, List<Integer> input) {
        if (s == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> str = new ArrayList<>(s.size() + input.size());
        int i = 0, j = 0;
        while (i < s.size() && j < input.size()) {
            if (s.get(i) <= input.get(j)) {
                str.add(s.get(i++));
            } else {
                str.add(input.get(j++));
            }
        }
        while (i < s.size()) {
            str.add(s.get(i++));
        }
        while (j < input.size()) {
            str.add(input.get(j++));
        }
        return str;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeHelper(int s) {
        if (s < 2) {
            return false;
        }
        for (int i = 2; i * i <= s; i++) {
            if (s % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int nums, int arr) {
        if (arr == 0) {
            throw new IllegalArgumentException("arr must not be zero");
        }
        return (double) nums / arr;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafeHelper(String s) {
        try {
            return Integer.parseInt(s);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + s);
            return 0;
        }
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int nums, int value) {
        if (value == 0) {
            throw new IllegalArgumentException("value must not be zero");
        }
        return (double) nums / value;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> input, List<Integer> value) {
        if (input == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> arr = new ArrayList<>(input.size() + value.size());
        int i = 0, j = 0;
        while (i < input.size() && j < value.size()) {
            if (input.get(i) <= value.get(j)) {
                arr.add(input.get(i++));
            } else {
                arr.add(value.get(j++));
            }
        }
        while (i < input.size()) {
            arr.add(input.get(i++));
        }
        while (j < value.size()) {
            arr.add(value.get(j++));
        }
        return arr;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString_v2(String s) {
        if (s == null) {
            return null;
        }
        return new StringBuilder(s).reverse().toString();
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_alt(String text) {
        try {
            return Integer.parseInt(text);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + text);
            return 0;
        }
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_v2(String text) {
        try {
            return Integer.parseInt(text);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + text);
            return 0;
        }
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> arr, List<Integer> nums) {
        if (arr == null || nums == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> str = new ArrayList<>(arr.size() + nums.size());
        int i = 0, j = 0;
        while (i < arr.size() && j < nums.size()) {
            if (arr.get(i) <= nums.get(j)) {
                str.add(arr.get(i++));
            } else {
                str.add(nums.get(j++));
            }
        }
        while (i < arr.size()) {
            str.add(arr.get(i++));
        }
        while (j < nums.size()) {
            str.add(nums.get(j++));
        }
        return str;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideEx(int value, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) value / list;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseStringHelper(String nums) {
        if (nums == null) {
            return null;
        }
        return new StringBuilder(nums).reverse().toString();
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> str, List<Integer> value) {
        if (str == null || value == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> value = new ArrayList<>(str.size() + value.size());
        int i = 0, j = 0;
        while (i < str.size() && j < value.size()) {
            if (str.get(i) <= value.get(j)) {
                value.add(str.get(i++));
            } else {
                value.add(value.get(j++));
            }
        }
        while (i < str.size()) {
            value.add(str.get(i++));
        }
        while (j < value.size()) {
            value.add(value.get(j++));
        }
        return value;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int nums, int s) {
        if (s == 0) {
            throw new IllegalArgumentException("s must not be zero");
        }
        return (double) nums / s;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> text) {
        if (text == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> list = new ArrayList<>(text.size() + text.size());
        int i = 0, j = 0;
        while (i < text.size() && j < text.size()) {
            if (text.get(i) <= text.get(j)) {
                list.add(text.get(i++));
            } else {
                list.add(text.get(j++));
            }
        }
        while (i < text.size()) {
            list.add(text.get(i++));
        }
        while (j < text.size()) {
            list.add(text.get(j++));
        }
        return list;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int value, int text) {
        if (text == 0) {
            throw new IllegalArgumentException("text must not be zero");
        }
        return (double) value / text;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> s, List<Integer> text) {
        if (s == null || text == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> input = new ArrayList<>(s.size() + text.size());
        int i = 0, j = 0;
        while (i < s.size() && j < text.size()) {
            if (s.get(i) <= text.get(j)) {
                input.add(s.get(i++));
            } else {
                input.add(text.get(j++));
            }
        }
        while (i < s.size()) {
            input.add(s.get(i++));
        }
        while (j < text.size()) {
            input.add(text.get(j++));
        }
        return input;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> list, List<Integer> input) {
        if (list == null || input == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> input = new ArrayList<>(list.size() + input.size());
        int i = 0, j = 0;
        while (i < list.size() && j < input.size()) {
            if (list.get(i) <= input.get(j)) {
                input.add(list.get(i++));
            } else {
                input.add(input.get(j++));
            }
        }
        while (i < list.size()) {
            input.add(list.get(i++));
        }
        while (j < input.size()) {
            input.add(input.get(j++));
        }
        return input;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted_v2(List<Integer> value, List<Integer> list) {
        if (value == null || list == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(value.size() + list.size());
        int i = 0, j = 0;
        while (i < value.size() && j < list.size()) {
            if (value.get(i) <= list.get(j)) {
                text.add(value.get(i++));
            } else {
                text.add(list.get(j++));
            }
        }
        while (i < value.size()) {
            text.add(value.get(i++));
        }
        while (j < list.size()) {
            text.add(list.get(j++));
        }
        return text;
    }
}


Instruction: Write a Java method that parses an integer from a string safely using try-catch.

Output:
public class Utils {

    public static int parseIntSafe_v2(String list) {
        try {
            return Integer.parseInt(list);
        } catch (NumberFormatException e) {
            System.err.println("Invalid number format: " + list);
            return 0;
        }
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int maxEx(int[] n) {
        if (n == null || n.length == 0) {
            throw new IllegalArgumentException("n must not be null or empty");
        }
        int max = n[0];
        for (int v : n) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that reverses a string.

Output:
public class StringUtils {

    public static String reverseString(String value) {
        if (value == null) {
            return null;
        }
        return new StringBuilder(value).reverse().toString();
    }
}


Instruction: Complete the following Java method so it returns the maximum value in an array.

Output:
public class ArrayUtils {

    public static int max_alt(int[] s) {
        if (s == null || s.length == 0) {
            throw new IllegalArgumentException("s must not be null or empty");
        }
        int max = s[0];
        for (int v : s) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSortedHelper(List<Integer> text, List<Integer> arr) {
        if (text == null || arr == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> nums = new ArrayList<>(text.size() + arr.size());
        int i = 0, j = 0;
        while (i < text.size() && j < arr.size()) {
            if (text.get(i) <= arr.get(j)) {
                nums.add(text.get(i++));
            } else {
                nums.add(arr.get(j++));
            }
        }
        while (i < text.size()) {
            nums.add(text.get(i++));
        }
        while (j < arr.size()) {
            nums.add(arr.get(j++));
        }
        return nums;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int value, int arr) {
        if (arr == 0) {
            throw new IllegalArgumentException("arr must not be zero");
        }
        return (double) value / arr;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_alt(int str, int text) {
        if (text == 0) {
            throw new IllegalArgumentException("text must not be zero");
        }
        return (double) str / text;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide(int value, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) value / list;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels_new(String arr) {
        if (arr == null) {
            return 0;
        }
        int count = 0;
        for (char c : arr.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowelsHelper(String text) {
        if (text == null) {
            return 0;
        }
        int count = 0;
        for (char c : text.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}


Instruction: Write a Java method that merges two sorted lists of integers into a new sorted list.

Output:
import java.util.ArrayList;
import java.util.List;

public class CollectionUtils {

    public static List<Integer> mergeSorted(List<Integer> s, List<Integer> arr) {
        if (s == null || arr == null) {
            throw new IllegalArgumentException("lists must not be null");
        }
        List<Integer> text = new ArrayList<>(s.size() + arr.size());
        int i = 0, j = 0;
        while (i < s.size() && j < arr.size()) {
            if (s.get(i) <= arr.get(j)) {
                text.add(s.get(i++));
            } else {
                text.add(arr.get(j++));
            }
        }
        while (i < s.size()) {
            text.add(s.get(i++));
        }
        while (j < arr.size()) {
            text.add(arr.get(j++));
        }
        return text;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divide_v2(int s, int n) {
        if (n == 0) {
            throw new IllegalArgumentException("n must not be zero");
        }
        return (double) s / n;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeEx(int list) {
        if (list < 2) {
            return false;
        }
        for (int i = 2; i * i <= list; i++) {
            if (list % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Fix the following Java method so it avoids division by zero.

Output:
public class MathUtils {

    public static double divideHelper(int nums, int list) {
        if (list == 0) {
            throw new IllegalArgumentException("list must not be zero");
        }
        return (double) nums / list;
    }
}


Instruction: Write a Java method that checks whether a number is prime.

Output:
public class MathUtils {

    public static boolean isPrimeHelper(int value) {
        if (value < 2) {
            return false;
        }
        for (int i = 2; i * i <= value; i++) {
            if (value % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Instruction: Write a Java method that counts the number of vowels in a string.

Output:
public class StringUtils {

    public static int countVowels(String input) {
        if (input == null) {
            return 0;
        }
        int count = 0;
        for (char c : input.toLowerCase().toCharArray()) {
            if ("aeiou".indexOf(c) >= 0) {
                count++;
            }
        }
        return count;
    }
}