I want to create a Map in a Java class, in which key is String and value is with type ArrayList<Double>. My requirement is that, if String equals some value, I could quickly pick up the corresponding list. All the lists are private variables in the same class.
Could someone please tell me where in the following code is wrong?
I got compilation error:
error: <identifier> expected METRICS_LIST_MAP.put("CPUUtilization", CPUUtilizationList);
My code:
private ArrayList<Double> CPUUtilizationList;
private ArrayList<Double> DiskReadOpsList;
private ArrayList<Double> DiskWriteOpsList;
private ArrayList<Double> DiskReadBytesList;
private ArrayList<Double> DiskWriteBytesList;
private ArrayList<Double> NetworkInList;
private ArrayList<Double> NetworkOutList;
Map<String, ArrayList<Double>> METRICS_LIST_MAP = new HashMap<String, ArrayList<Double>>();
METRICS_LIST_MAP.put("CPUUtilization", CPUUtilizationList);
METRICS_LIST_MAP.put("DiskReadOps", DiskReadOpsList);
METRICS_LIST_MAP.put("DiskWriteOps", DiskWriteOpsList);
METRICS_LIST_MAP.put("DiskReadBytes", DiskReadBytesList);
METRICS_LIST_MAP.put("DiskWriteBytes", DiskWriteBytesList);
METRICS_LIST_MAP.put("NetworkIn", NetworkInList);
METRICS_LIST_MAP.put("NetworkOut", NetworkOutList);
Thanks!
put(...)method out there and instead can only declare or declare and initialize variables and constants. Also, always post the complete error message. Yours may be missing important statements.putstatements in{}, this is called an "instance initialiser" and will be copied to the constructor.