I have two arrays with the same length in my program, courseGrades and courseCredits, that look something like this:
courseGrades[] = {A, A, B, A, C, A};
courseCredits[] = {1, 2, 1, 3, 2, 1};
I want to combine them into one two-dimensional array that would display like this:
A A B A C A
1 2 1 3 2 1
How would I do this in Java? Additionally, how would you refer to each element in this array? Sorry for the very simple question, I'm still a beginner at java.
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.