문제

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