mardi 5 décembre 2017

Readable key value pair data-structure in java

I have a key value arrays

String[] fields      = {"firstName", "middleName", "id"};
String[] fieldValues = {"first name", "middle name", "student id"};

I have a method, that builds a complex java POJO bean with the arrays

  public static MyBean buildMyBean(MyBean original, String[] fields, String[] fieldValues) {
  HashMap<String , MyBean> reqFields = new HashMap<String , MyBean>();
  original.setUnmatchedValue(reqFields);

    for(int i = 0; i< fields.length; i++ ) {
        String key = fields[i] + ":" + fieldValues[i];
        reqFields.put(key, null);
        }

    return original;
}

Is there a better and more readable way to combine both fields and fieldValues?

I have 100's of methods with 100's of different fields.

Aucun commentaire:

Enregistrer un commentaire