Wie kann eine Schleife beschleunigt werden, die Zeichenfolgen in Java bearbeitet? [geschlossen]

Ich habe ein Programm, das eine Zeichenfolge in einer Schleife erstellt, und mein Programm ist zu langsam. Die Ausführung dauert jetzt etwa 600 MillisekundenOblig1Test.oppgave7. Was könnte getan werden, um es zu beschleunigen?

Oblig1.toString:

public static String toString(int[] a, char v, char h, String mellomrom)
{
    String s ="";

    s += v;

    if(a.length != 0)
    {
        for(int i = 0; i < a.length-1; i++)
        {
                s += a[i] + mellomrom; 
        }

        s += a[a.length-1];
    }

    s += h;

    return s;
}

Oblig1Test:

public static int oppgave7()
{
   int[] b = new int[20000];
   long tid = System.currentTimeMillis();
   Oblig1.toString(b,' ',' '," ");
   tid = System.currentTimeMillis() - tid;

  if (tid > 40)
  {
    System.out.println("Oppgave 7: Metoden "
      + "er for ineffektiv. Må forbedres!");
  }
}

public static void main(String[] args) throws IOException
{
   oppgave7();
}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage