Switch case implementation in Java for an integer pair combination I have following Python code:

def get_subject_from_stream_id_and_subject_id(stream_id, subject_id):
    #(stream_id, subject_id): ("subject_name")
    return {
        (1, 1): "Accounts",
        (1, 2): "English",
        (1, 3): "Organization of Commerce",
        (2, 1): "Physics",
        (2, 2): "English",
        (2, 3): "Biology"
    }.get((stream_id, subject_id), "None")


In this code, I want to get subject name from the integer pair combination i.e. stream_id, subject_id e.g. (1, 2) is for English. It was implemented using a Python tuple.

I want to implement the same piece of code in Java.

Could someone write this in a better way in Java? 

public String getSubjectFromStreamIdAndSubjectId(int streamId, int subjectId) {
  switch (streamId) {
    case 1:
        switch (subjectId) {
        case 1:
            return "Accounts";
        case 2:
            return "English";
        case 3:
            return "Organization of Commerce";
        default:
            return null;
        }

    case 2:
        switch (subjectId) {
        case 1:
            return "Physics";
        case 2:
            return "English";
        case 3:
            return "Biology";
        default:
            return null;
        }
    default:
        return null;
   }
}
Neither is good, but surely we can all agree that the Java example is way uglier. The biggest problem, however, is that both examples hard code data into code.

Separate data, i.e. stream and subject IDs and their titles into a data class and in that class implement code that accesses the data structure without detailed knowledge about the actual data. Responsibility of setting up the data structure to resemble your stream and subject numbering is left to a separate component (load it from file or set up in static code).

Whether the data class is a recursive structure or just a wrapper for a HashMap depends on the complexity of your data.