# Creating matrix using a sorted array

• 12-22-2013, 08:49 PM
Omer1233
Creating matrix using a sorted array
say I'm given a sorted array of strings : {Max,Max,Max,Omer,Omer} How can i make a matrix that contains in each row the same names:

Max , Max , Max

Omer , Omer

its a matrix of employees, so ive tried the following:

Code:

```public static Employee[][] initMat(Employee[] eps)     {         Employee[][] mat = new Employee[eps.length][eps.length];         for(int i = 0;i < mat.length-1; i++)         {             for(int j=i;j<mat[i].length-1;j++)             {                 if(eps[i].getName().equals(eps[i+1].getName()))                     {                         mat[i][j] = eps[i];                         mat[i][j+1] = eps[i+1];                     }             }         }         return mat;```
Ty!
• 12-22-2013, 09:16 PM
Norm
Re: Creating matrix using a sorted array
Can you post the desired output for the String array you posted?
What is in the array if there are fewer matching names on a row?
• 12-22-2013, 09:33 PM
Omer1233
Re: Creating matrix using a sorted array
With this given array : {Max,Max,Max,Omer,Omer}

We should get this matrix
|Max , Max , Max|
|Omer , Omer|

Ty for the quick response!
• 12-22-2013, 09:56 PM
Norm
Re: Creating matrix using a sorted array
Ok, that looks like every row in the 2 dim array can be a different length. Is that correct?
If all the names are the same, there would only be one row.

Now work on the logic for scanning through the 1 dim array separating its contents into the rows for the two dim array.
Work out the details of the logic before trying to write the code.
You'll need to determine the number of rows and the length of each row.