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)
if the dept-age calculations are very important for your business logic, you could consider to create a new type like `DeptAgeStat`.
It has:

```
String name;
List<Integer> allAges;

List<Integer> getGroup1(){//return new List, or a ListView of allAges};
List<Integer> getGroup2(){//same as above};
...

List<Integer> getAgesWithWhateverPartitionCondidtions(here could have condition para see below text){...};

```

this will ease your future calculation. If it is necessary, e.g. you could have different criteria to filter/group ages in future, you can even design a `PartitionCriteria` type as parameter to those methods. again, it depends on the requirement. 

Hope it helps.