Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top