Dataset Viewer
Auto-converted to Parquet Duplicate
instruction
stringclasses
7 values
input
stringclasses
1 value
output
stringlengths
204
833
language
stringclasses
1 value
category
stringclasses
4 values
difficulty
stringclasses
2 values
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_new(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; } }
java
completion
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_new(String nums) { try { return Integer.parseInt(nums); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + nums); return 0; } } }
java
exception-handling
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_v2(int s, int value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) s / value; } }
java
bug-fix
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringHelper(String value) { if (value == null) { return null; } return new StringBuilder(value).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int input, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) input / nums; } }
java
bug-fix
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_new(int s) { if (s < 2) { return false; } for (int i = 2; i * i <= s; i++) { if (s % i == 0) { return false; } } return true; } }
java
function
medium
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(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; } }
java
completion
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_v2(String n) { try { return Integer.parseInt(n); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + n); return 0; } } }
java
exception-handling
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int value, int text) { if (text == 0) { throw new IllegalArgumentException("text must not be zero"); } return (double) value / text; } }
java
bug-fix
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_alt(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; } }
java
completion
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_new(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; } }
java
completion
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringEx(String n) { if (n == null) { return null; } return new StringBuilder(n).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_new(int str, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) str / nums; } }
java
bug-fix
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_alt(String arr) { if (arr == null) { return 0; } int count = 0; for (char c : arr.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(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; } }
java
completion
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int n) { if (n < 2) { return false; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted_v2(List<Integer> text, List<Integer> arr) { if (text == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> text = 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)) { text.add(text.get(i++)); } else { text.add(arr.get(j++)); } } while (i < text.size()) { text.add(text.get(i++)); } while (j < arr.size()) { text.add(arr.get(j++)); } return text; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafeHelper(String input) { try { return Integer.parseInt(input); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + input); return 0; } } }
java
exception-handling
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_alt(int text) { if (text < 2) { return false; } for (int i = 2; i * i <= text; i++) { if (text % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafeHelper(String n) { try { return Integer.parseInt(n); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + n); return 0; } } }
java
exception-handling
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(int s) { if (s < 2) { return false; } for (int i = 2; i * i <= s; i++) { if (s % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringEx(String input) { if (input == null) { return null; } return new StringBuilder(input).reverse().toString(); } }
java
function
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_v2(String value) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + value); return 0; } } }
java
exception-handling
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int s, int input) { if (input == 0) { throw new IllegalArgumentException("input must not be zero"); } return (double) s / input; } }
java
bug-fix
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int text, int text) { if (text == 0) { throw new IllegalArgumentException("text must not be zero"); } return (double) text / text; } }
java
bug-fix
easy
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedHelper(List<Integer> str, List<Integer> arr) { if (str == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> arr = new ArrayList<>(str.size() + arr.size()); int i = 0, j = 0; while (i < str.size() && j < arr.size()) { if (str.get(i) <= arr.get(j)) { arr.add(str.get(i++)); } else { arr.add(arr.get(j++)); } } while (i < str.size()) { arr.add(str.get(i++)); } while (j < arr.size()) { arr.add(arr.get(j++)); } return arr; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int n, int list) { if (list == 0) { throw new IllegalArgumentException("list must not be zero"); } return (double) n / list; } }
java
bug-fix
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int value, int value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) value / value; } }
java
bug-fix
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int n, int str) { if (str == 0) { throw new IllegalArgumentException("str must not be zero"); } return (double) n / str; } }
java
bug-fix
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_new(int list) { if (list < 2) { return false; } for (int i = 2; i * i <= list; i++) { if (list % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted_v2(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; } }
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int value) { if (value < 2) { return false; } for (int i = 2; i * i <= value; i++) { if (value % i == 0) { return false; } } return true; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int text, int input) { if (input == 0) { throw new IllegalArgumentException("input must not be zero"); } return (double) text / input; } }
java
bug-fix
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringHelper(String text) { if (text == null) { return null; } return new StringBuilder(text).reverse().toString(); } }
java
function
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int maxEx(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; } }
java
completion
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max(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; } }
java
completion
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int arr) { if (arr < 2) { return false; } for (int i = 2; i * i <= arr; i++) { if (arr % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_alt(String str) { try { return Integer.parseInt(str); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + str); return 0; } } }
java
exception-handling
medium
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(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; } }
java
completion
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringEx(String nums) { if (nums == null) { return null; } return new StringBuilder(nums).reverse().toString(); } }
java
function
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_v2(String str) { try { return Integer.parseInt(str); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + str); return 0; } } }
java
exception-handling
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted(List<Integer> nums, List<Integer> arr) { if (nums == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> list = new ArrayList<>(nums.size() + arr.size()); int i = 0, j = 0; while (i < nums.size() && j < arr.size()) { if (nums.get(i) <= arr.get(j)) { list.add(nums.get(i++)); } else { list.add(arr.get(j++)); } } while (i < nums.size()) { list.add(nums.get(i++)); } while (j < arr.size()) { list.add(arr.get(j++)); } return list; } }
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrimeEx(int str) { if (str < 2) { return false; } for (int i = 2; i * i <= str; i++) { if (str % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_alt(String list) { try { return Integer.parseInt(list); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + list); return 0; } } }
java
exception-handling
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
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> text = 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)) { text.add(list.get(i++)); } else { text.add(list.get(j++)); } } while (i < list.size()) { text.add(list.get(i++)); } while (j < list.size()) { text.add(list.get(j++)); } return text; } }
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int nums) { if (nums < 2) { return false; } for (int i = 2; i * i <= nums; i++) { if (nums % i == 0) { return false; } } return true; } }
java
function
medium
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int maxEx(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; } }
java
completion
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(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; } }
java
completion
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_new(int text) { if (text < 2) { return false; } for (int i = 2; i * i <= text; i++) { if (text % i == 0) { return false; } } return true; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int str, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) str / nums; } }
java
bug-fix
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_v2(String arr) { if (arr == null) { return null; } return new StringBuilder(arr).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int value, int value) { if (value == 0) { throw new IllegalArgumentException("value must not be zero"); } return (double) value / value; } }
java
bug-fix
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_v2(int[] text) { if (text == null || text.length == 0) { throw new IllegalArgumentException("text must not be null or empty"); } int max = text[0]; for (int v : text) { if (v > max) { max = v; } } return max; } }
java
completion
easy
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedEx(List<Integer> nums, List<Integer> text) { if (nums == null || text == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = new ArrayList<>(nums.size() + text.size()); int i = 0, j = 0; while (i < nums.size() && j < text.size()) { if (nums.get(i) <= text.get(j)) { nums.add(nums.get(i++)); } else { nums.add(text.get(j++)); } } while (i < nums.size()) { nums.add(nums.get(i++)); } while (j < text.size()) { nums.add(text.get(j++)); } return nums; } }
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_alt(int input) { if (input < 2) { return false; } for (int i = 2; i * i <= input; i++) { if (input % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedHelper(List<Integer> list, List<Integer> text) { if (list == null || text == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> s = 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)) { s.add(list.get(i++)); } else { s.add(text.get(j++)); } } while (i < list.size()) { s.add(list.get(i++)); } while (j < text.size()) { s.add(text.get(j++)); } return s; } }
java
function
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowelsEx(String s) { if (s == null) { return 0; } int count = 0; for (char c : s.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels(String s) { if (s == null) { return 0; } int count = 0; for (char c : s.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowels_new(String text) { if (text == null) { return 0; } int count = 0; for (char c : text.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_new(int arr) { if (arr < 2) { return false; } for (int i = 2; i * i <= arr; i++) { if (arr % i == 0) { return false; } } return true; } }
java
function
medium
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max(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; } }
java
completion
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(int list) { if (list < 2) { return false; } for (int i = 2; i * i <= list; i++) { if (list % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_v2(String arr) { try { return Integer.parseInt(arr); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + arr); return 0; } } }
java
exception-handling
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_alt(String s) { try { return Integer.parseInt(s); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + s); return 0; } } }
java
exception-handling
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_alt(String n) { try { return Integer.parseInt(n); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + n); return 0; } } }
java
exception-handling
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted_new(List<Integer> nums, List<Integer> n) { if (nums == null || n == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> arr = new ArrayList<>(nums.size() + n.size()); int i = 0, j = 0; while (i < nums.size() && j < n.size()) { if (nums.get(i) <= n.get(j)) { arr.add(nums.get(i++)); } else { arr.add(n.get(j++)); } } while (i < nums.size()) { arr.add(nums.get(i++)); } while (j < n.size()) { arr.add(n.get(j++)); } return arr; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int input, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) input / nums; } }
java
bug-fix
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int max_new(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; } }
java
completion
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringEx(String s) { if (s == null) { return null; } return new StringBuilder(s).reverse().toString(); } }
java
function
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowelsEx(String input) { if (input == null) { return 0; } int count = 0; for (char c : input.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_alt(int list, int list) { if (list == 0) { throw new IllegalArgumentException("list must not be zero"); } return (double) list / list; } }
java
bug-fix
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_new(String arr) { try { return Integer.parseInt(arr); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + arr); return 0; } } }
java
exception-handling
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedEx(List<Integer> value, List<Integer> text) { if (value == null || text == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> list = 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)) { list.add(value.get(i++)); } else { list.add(text.get(j++)); } } while (i < value.size()) { list.add(value.get(i++)); } while (j < text.size()) { list.add(text.get(j++)); } return list; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int n, int s) { if (s == 0) { throw new IllegalArgumentException("s must not be zero"); } return (double) n / s; } }
java
bug-fix
easy
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedEx(List<Integer> value, List<Integer> text) { if (value == null || text == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> arr = 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)) { arr.add(value.get(i++)); } else { arr.add(text.get(j++)); } } while (i < value.size()) { arr.add(value.get(i++)); } while (j < text.size()) { arr.add(text.get(j++)); } return arr; } }
java
function
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_alt(int s) { if (s < 2) { return false; } for (int i = 2; i * i <= s; i++) { if (s % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedHelper(List<Integer> arr, List<Integer> n) { if (arr == null || n == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> list = new ArrayList<>(arr.size() + n.size()); int i = 0, j = 0; while (i < arr.size() && j < n.size()) { if (arr.get(i) <= n.get(j)) { list.add(arr.get(i++)); } else { list.add(n.get(j++)); } } while (i < arr.size()) { list.add(arr.get(i++)); } while (j < n.size()) { list.add(n.get(j++)); } return list; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted_new(List<Integer> nums, List<Integer> str) { if (nums == null || str == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> input = 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)) { input.add(nums.get(i++)); } else { input.add(str.get(j++)); } } while (i < nums.size()) { input.add(nums.get(i++)); } while (j < str.size()) { input.add(str.get(j++)); } return input; } }
java
function
medium
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe_v2(String input) { try { return Integer.parseInt(input); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + input); return 0; } } }
java
exception-handling
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_alt(String list) { if (list == null) { return null; } return new StringBuilder(list).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_new(int text, int nums) { if (nums == 0) { throw new IllegalArgumentException("nums must not be zero"); } return (double) text / nums; } }
java
bug-fix
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime(int input) { if (input < 2) { return false; } for (int i = 2; i * i <= input; i++) { if (input % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedEx(List<Integer> input, List<Integer> input) { if (input == null || input == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> nums = 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)) { nums.add(input.get(i++)); } else { nums.add(input.get(j++)); } } while (i < input.size()) { nums.add(input.get(i++)); } while (j < input.size()) { nums.add(input.get(j++)); } return nums; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSorted(List<Integer> input, List<Integer> nums) { if (input == null || nums == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> text = 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)) { text.add(input.get(i++)); } else { text.add(nums.get(j++)); } } while (i < input.size()) { text.add(input.get(i++)); } while (j < nums.size()) { text.add(nums.get(j++)); } return text; } }
java
function
medium
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowelsHelper(String list) { if (list == null) { return 0; } int count = 0; for (char c : list.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(int n) { if (n < 2) { return false; } for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideHelper(int s, int list) { if (list == 0) { throw new IllegalArgumentException("list must not be zero"); } return (double) s / list; } }
java
bug-fix
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafe(String s) { try { return Integer.parseInt(s); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + s); return 0; } } }
java
exception-handling
medium
Write a Java method that checks whether a number is prime.
public class MathUtils { public static boolean isPrime_v2(int nums) { if (nums < 2) { return false; } for (int i = 2; i * i <= nums; i++) { if (nums % i == 0) { return false; } } return true; } }
java
function
medium
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedHelper(List<Integer> list, List<Integer> n) { if (list == null || n == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> arr = new ArrayList<>(list.size() + n.size()); int i = 0, j = 0; while (i < list.size() && j < n.size()) { if (list.get(i) <= n.get(j)) { arr.add(list.get(i++)); } else { arr.add(n.get(j++)); } } while (i < list.size()) { arr.add(list.get(i++)); } while (j < n.size()) { arr.add(n.get(j++)); } return arr; } }
java
function
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divideEx(int nums, int text) { if (text == 0) { throw new IllegalArgumentException("text must not be zero"); } return (double) nums / text; } }
java
bug-fix
easy
Write a Java method that merges two sorted lists of integers into a new sorted list.
import java.util.ArrayList; import java.util.List; public class CollectionUtils { public static List<Integer> mergeSortedEx(List<Integer> n, List<Integer> arr) { if (n == null || arr == null) { throw new IllegalArgumentException("lists must not be null"); } List<Integer> input = new ArrayList<>(n.size() + arr.size()); int i = 0, j = 0; while (i < n.size() && j < arr.size()) { if (n.get(i) <= arr.get(j)) { input.add(n.get(i++)); } else { input.add(arr.get(j++)); } } while (i < n.size()) { input.add(n.get(i++)); } while (j < arr.size()) { input.add(arr.get(j++)); } return input; } }
java
function
medium
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_alt(String input) { if (input == null) { return null; } return new StringBuilder(input).reverse().toString(); } }
java
function
easy
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_new(int text, int str) { if (str == 0) { throw new IllegalArgumentException("str must not be zero"); } return (double) text / str; } }
java
bug-fix
easy
Complete the following Java method so it returns the maximum value in an array.
public class ArrayUtils { public static int maxHelper(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; } }
java
completion
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseStringEx(String arr) { if (arr == null) { return null; } return new StringBuilder(arr).reverse().toString(); } }
java
function
easy
Write a Java method that counts the number of vowels in a string.
public class StringUtils { public static int countVowelsEx(String value) { if (value == null) { return 0; } int count = 0; for (char c : value.toLowerCase().toCharArray()) { if ("aeiou".indexOf(c) >= 0) { count++; } } return count; } }
java
function
easy
Write a Java method that parses an integer from a string safely using try-catch.
public class Utils { public static int parseIntSafeEx(String nums) { try { return Integer.parseInt(nums); } catch (NumberFormatException e) { System.err.println("Invalid number format: " + nums); return 0; } } }
java
exception-handling
medium
Fix the following Java method so it avoids division by zero.
public class MathUtils { public static double divide_v2(int str, int str) { if (str == 0) { throw new IllegalArgumentException("str must not be zero"); } return (double) str / str; } }
java
bug-fix
easy
Write a Java method that reverses a string.
public class StringUtils { public static String reverseString_alt(String arr) { if (arr == null) { return null; } return new StringBuilder(arr).reverse().toString(); } }
java
function
easy
End of preview. Expand in Data Studio

Java Coding Dataset

This dataset contains high-quality Java code samples designed for fine-tuning coding-focused language models. It includes a diverse set of examples such as utility functions, class definitions, interface implementations, and exception handling.

Dataset Details

  • Number of samples: 520 (and growing)
  • Purpose: Fine-tuning LLMs to generate accurate and idiomatic Java code
  • Content: Functions, classes, interfaces, exception handling
  • License: MIT License

Usage

You can use this dataset with Hugging Face libraries or any fine-tuning pipeline compatible with JSONL data.

Example to load with datasets library:

from datasets import load_dataset
dataset = load_dataset("Hoglet-33/java-coding-dataset")
print(dataset["train"][0])
Downloads last month
8