title: How to add and modify prefix in Java, using String arrays?
body: <p>The essence of the problem is:
  Implement a <strong>public static addPrefix()</strong> method that takes an array of strings and a string prefix as input and returns a new array in which the given prefix is added to each element of the original array. A space is automatically added after the prefix.</p>
  <p><strong>How the program should work:</strong></p>
  <pre><code>String[] names = {&quot;John&quot;, &quot;Smit&quot;, &quot;Karl&quot;};
  var namesWithPrefix = App.addPrefix(names, &quot;Mr.&quot;);
  
  System.out.println(Arrays.toString(namesWithPrefix));
  // =&gt; [&quot;Mr. John&quot;, &quot;Mr. Smit&quot;, &quot;Mr. Karl&quot;]
  
  System.out.println(Arrays.toString(names)); //  The original array does not change
  
  // =&gt; [&quot;John&quot;, &quot;Smit&quot;, &quot;Karl&quot;]
  
  </code></pre>
  <p><strong>Here is my code:</strong></p>
  <pre><code>public class App {
     
      public static String[] addPrefix(String[] names, String[] prefixes){
         
         String[] result= new String[names.length];
         String sequence =&quot;&quot;+ names[0]+prefixes[0];
         result[0]=&quot;[&quot;+ sequence+&quot;]&quot;;
  
         for(int i=1; i&lt;names.length;i++){
             sequence+=&quot;, &quot;+names[i];
             result[i] =&quot;[&quot; + sequence +&quot;]&quot;;
         }
         return result;
      }
      
  }
  </code></pre>