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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top