Question: I have a table to store the region in every **client** like this

```
{id, name, ....}

```

User can choose one of the region and I need to save it. Notice that only **one** region can be selected. 

**SOLUTION 1:**  

Add a new column called selected and add index based on this column. 

So every time user select a region, I need to run two update SQL. 

```
UPDATE table set selected = 0 where selected = 1
Update table set selected = 1 where id = xxx

```

When I need to retrieve the selected region, run the query

```
SELECT * from table where selected = 1

```

It works but seems not well designed. First of all, the space usage is not good as I add a new column. And the performance is not good too because every time I need to run two update query when user select another region.

**SOLUTION 2:**  

If I open a new table to save the selected region id, it seems quite strange to have just one row in a table.

Answer: 
When you want to add values at a specific index in arraylist without increasing its length , it is better to use set method from arraylist.
Use
ArrayList.set(int index, E element)
You must use set method instead of add methods i.e. `array.set(index, value);`.