Cartesian Product on an Array of Strings using JAVA
<p>I'm not sure about the title of the question, please feel free to edit it!</p>

<p>Anyway, here is the problem description:</p>

<p>I have a data structure, to hold relational information between two pairs:</p>

<pre><code>Class Relation
{
    Public String Source;
    Public String Destination;
    Public String Relate;
}
</code></pre>

<p>In my program, I have the following initialization to encode different relations between two sets of entities:</p>

<pre><code>String []Subjects = new String [10]; // Consider having S1, S2, S3
String []Objects = new String [10]; // Consider having O1, O2
Relation []AllRelations = new Relation[100];
//Consider having the following rerlations in AllRelations array:
/*
S1 Read O1
S1 Write O1
O1 Delete S2
O1 Add S2
S2 Update S3
S3 Execute O3
*/
</code></pre>

<p>I need to iterate through the AllRelations array, to find all possible relations. The output should be an array of strings where each string holds the possible relations between two given entities. There is no need to have the Source and Destination in the output array.</p>

<p>In the example given, the output should be something like:</p>

<pre><code>Read-Delete-Update-Execute

Read-Add-Update-Execute

Write-Delete-Update-Execute

Write-Add-Update-Execute
</code></pre>

<p>I was trying to solve this problem with an iterative approach "loops", but I failed. Also, I'm trying to consider recursion and I have no idea how to start.</p>

<p>Any suggestions are welcome!</p>
