Frage

I have a question, I have created a method toString(), I want this method to print out two strings a int[] and a char. While using String.format(), how would one go about this?

War es hilfreich?

Lösung

One quick way to print out the guys, includes

@Override
public String toString() {
  return String.format("%s %c", java.util.Arrays.toString(intArray), myChar);
}

But who knows if this is the output you want? The devil's in the details of your desired output. Your question is very incomplete, very vague. Please consider giving us more of the important details of just what you're trying to achieve and how your current code does or doesn't work.

Andere Tipps

What you are probably looking for is:

String.format("%s %s %s %c", string1, string2, Arrays.toString(array), character);

Be sure to import java.util.Arrays for this to work.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top