Question: I have a hashmap of type `Map<String, List<Integer>> empage` where `String` is the name of the department and `List` is the list of age of employees who work in that department.

Now for each department I want to divide the age of employees into 5 age categories like (0-20,20-40...and so on).How can I create these 5 list variables for each department dynamically? I mean I cannot hardcode variable name like `Finance_grp1` and so on for each department name? So basically I want something like:

```
for(each departname in empage.keyset())
{
create Arraylist departmentname_grp1
create Arraylist departmentname_grp2
create Arraylist departmentname_grp3
.
.
and so on till 5 groups
}

```

For Example the structure that I want is something like this:

```
Department Finance
grp1 for age 0-20
grp2 for age 20-40
and so on till grp5

Department HR
grp1 for age 0-20
grp2 for age 20-40
and so on till grp5

```

This way for all the department names, I want to group employees age into groups 

Also after creating these 5 groups and processing the employee age into categories, I want to variable of type `ChartSeries` for each department name which then I will add to create a bar chart.So, I want something like:

```
for(department_name in empage)
{
ChartSeries department_name = new ChartSeries();
}

```

Can anyone help me in resolving this issue?

**UPDATE:** I know that in Java we cannot append dynamic string while creating variables. What I want is the possible solution to this issue and above problem

Answer: 
The basic answer to your question is you cannot dynamically assign variable names in Java. Here's another SO post that has more potential ways around this: [Assigning Dynamic Variable Names](https://stackoverflow.com/questions/6729605/assigning-variables-with-dynamic-names-in-java)
Alright I think I see better what you're trying to do, but ultimately the answer to your question is still to use an appropriate collection. Try something like this:

```
Map<Department, Map<Integer, List<Employee>>> departmentEmployeeAgeMap;

```

where Integer is the age bracket they fall into 0-20 being 0, 20-40 being 1, and so on. This assumes you have a department class, if you don't you could use String to represent the department names as well.

This way when you want to store an employee they are accessible by a department key and then an Integer age range key.

So if you need to add employees to the groups you would go like this:

```
Map<Department, Map<Integer, List<Employee>>> departmentEmployeeAgeMap = new Map<Department, Map<Integer, ArrayList<Employee>>>();
Map<Integer, List<Employee>> currentDepartmentAgeMap;

for(department : departments) {
    departmentEmployeeAgeMap.put(department, new Map<Integer, List<Employee>>());
    currentDepartmentAgeMap = departmentEmployeeAgeMap.get(department);
    for(int i=0; i<5; i++) {
        currentDepartmentAgeMap.put(i, new ArrayList<Employee>());
    }
    for(employee : department) {
        currentDepartmentAgeMap.get(employee.getAge()/20).add(employee);
    }
}

```

And then accessing this datastructure to pull the employees back out is easy:

```
departmentEmployeeAgeMap.get(department).get(1);

```

Will retrieve a list of all the employees who work in a given department between the ages of 20-39.

If you really want to be able to create dynamic variable names you should consider another language other than java. This is not how Java was intended to function and it does not do this well.