Can a Java List be output as a String? -


If I want to print string "output", after which any method results, only one will do the same On the same line, "Output:" is a method that returns the string type. For example:

  public static zero main (string [] args) {System.out.println (return string ("hello")); } Public stable string return string (string s) {return "output:" + s; }  

If, I want to print the string "output", then after returning any other variable type method, the return will be on a different line. For example:

  public static zero main (string [] args) {System.out.println (returning (2)); } Pubic static intricate returning (int n) {System.out.println ("Output:"); Return n; }  

or by changing the return type to a string and using an implicit conversion method that is suitable for return type. For example:

  public static zero main (string [] args) {System.out.println (returning (2)); } Public static string returning (int n) {return "output:" + string.valouf (n)}  

or

  public static zero main string [] Args) {System.out.println (return again (new int [] {1, 2, 3})); } Public Fixed String Return Returns (int [] array) {Return "Output:" + Arrays.toString (array); }  

or

  public static zero main (string [] args) {System.out.println (returnboard (wrong)); } Public stable string return boolean (boolean B) {return "output:" + boolean. Tosting (B); }  

Then there are three questions:

1) It is not possible to declare two types of two types while repeating the method (ie methodName (not correct?

2) Is there a way (such as escape sequence) that pulls the next line back to the OT in the same row?

2) And if not, return to the list There is an underlying method (for the way that Arrays.toString or String.value do for their respective types? I do not have a similar list In the can. Tostring etc.

1) That's right. One method can return an object that contains multiple types of example variables.

2) If you use system.out instead of system.out.print () .println () Line will not add

3) Provides an easy way to print elements of a list.

  System.out.println (Arrays.toString (stack.toArray ()));  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -