fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11.  
  12. // public void addCarriages(Carriage [] carriageCoupes, Carriage[] carriagePKs){
  13. // arrayOfCarriages = new Carriage[carriageCoupes.length + carriagePKs.length];
  14. // System.arraycopy(carriagePKs, 0, arrayOfCarriages, 0, carriagePKs.length);
  15. // System.arraycopy(carriageCoupes, 0, arrayOfCarriages, carriagePKs.length, carriageCoupes.length);
  16. // }
  17.  
  18. static public String[] joinArrays(String[] carriageCoupes, String[] carriagePKs){
  19. String[] arrayOfCarriages = new String[carriageCoupes.length + carriagePKs.length];
  20. System.arraycopy(carriagePKs, 0, arrayOfCarriages, 0, carriagePKs.length);
  21. System.arraycopy(carriageCoupes, 0, arrayOfCarriages, carriagePKs.length, carriageCoupes.length);
  22.  
  23. return arrayOfCarriages;
  24. }
  25.  
  26. public static void main(String[] args) throws Exception {
  27. String[] a = Stream.generate( () -> "a" ).limit( 3 ).toArray(String[]::new);
  28. String[] b = Stream.generate( () -> "b" ).limit( 7 ).toArray(String[]::new);
  29.  
  30. System.out.println( Arrays.toString( joinArrays( a, b ) ) );
  31. }
  32. }
Success #stdin #stdout 0.09s 711168KB
stdin
Standard input is empty
stdout
[b, b, b, b, b, b, b, a, a, a]