Java multidimensional array for android app

I am currently making an application that will have many exercises (for development), each with 5 different lines. They are related to workouts, which are basically arrays of exercises (but more than one workout can have the same exercise and I don't want to waste memory) and then the workouts are displayed in different categories (weight loss, bodybuilding, etc.) ..).

If I were doing this in C (which is the language I usually program in), I would have the exercises as an array of a structure called an exercise, then the exercise would be linked lists with each reference being a pointer to an exercise, with int for repetitions, and int for sets. And the workouts will be organized into an array of pointer pointing to the first element of the linked list (so the workout can be in multiple categories). Is there a way to implement something like this in java?

+3


source to share


1 answer


Working backwards from your method in c, why not have something like:

class Exercise {
 private String exName;
 private int reps;
 private int sets;

      

And creating a constructor:

 public Exercise(String newName, int newReps, int newSets) {
  exName = newName;
  reps = newReps;
  sets = newSeats;

      

This is really the only part that is different from c.

Here all you do is make an Exercise object that contains the information you need, repetitions, and sets.



The constructor creates a new instance of the object.

Then you can just use a regular arraylist for exercise list and workout list.

So, you get what you can imagine:

[[Exercise1, Exercise2, ...][Exercise1, Exercise2, ....]...]

      

So the outermost list is your workout allocator, the internal list is your exercise allocator for each workout, and each exercise is a structure that contains an (optional) name along with its list of repetitions and sets.

+4


source







All Articles