You seem to want to combine an array of strings with an array of ints into a 2D array.
In Java, 2D arrays can only store one kind of thing, so there is no type-safe way to do this. A type-unsafe way to do this would be to store them in an Object[][]:
String[] grades = {"A", "B", "C"}; Integer[] credits = {1, 2, 3}; Object[][] gradesAndCredits = { grades, credits }; for (int i = 0; i < gradesAndCredits.length ; i++) { for (int j = 0 ; j < gradesAndCredits[i].length ; j++) { System.out.print(gradesAndCredits[i][j] + " "); } System.out.println(); }
If you want the items in the subarrays as Strings and Integers, you'd need to cast them, which is type-unsafe.
Alternatively, you can store these pairs in a HashMap if it makes sense for one of them to act as the "key" and the other the "value".
String[] grades = {"A", "B", "C"}; Integer[] credits = {1, 2, 3}; HashMap<String, Integer> map = new HashMap<>(); for (int i = 0 ; i < grades.length ; i++) { map.put(grades[i], credits[i]); }
courseGradesandcourseCreditstoObject[], then you can have your expected result asObject[][] results = new Object[][2](); result[0] = courseGrades; result[1] = courseCredits;and no memory copying will happen. Still, if you want to remember that one array holdsints and the other -Strings, then you're out of luck. What you actually need to do is to createCourseclass that will keepgradeandcredit- then you make an array ofCourses instead of two arrays for its parts.