About 2,730,000 results
Open links in new tab
  1. How to Return a String in Java - Delft Stack

    Feb 2, 2024 · In this Java program, the returnString() method is designed to fulfill a simple purpose — it returns a string. Specifically, in this example, the string the method returns is "Hello, World!". This method serves as an example of how a function in Java can produce a string output.

  2. Returning String Methods in Java? - Stack Overflow

    When something says return x (for any value of x), it is saying to terminate the current method call and yield the value x to whoever called the method. For example, consider the expression 2 + 3 . If you were to say int x = 2 + 3 , you would expect x to have value 5 afterwards.

  3. function to return a string in java - Stack Overflow

    Jan 25, 2012 · public String time_to_string(long t) // time in milliseconds { if (t < 0) { return "-"; } else { int secs = (int)(t/1000); int mins = secs/60; secs = secs - (mins * 60); return String.format("%d:%02d", mins, secs); } }

  4. java - Return value for String method - Stack Overflow

    Sep 26, 2013 · public String takeNames(String fName, String lName){ Scanner scanner = new Scanner(System.in); System.out.println("Enter your first and last name"); fName = scanner.next(); lName = scanner.next(); return String.format("Hello %s %s", fName, lName); }

  5. How to Return a String in Java: A Comprehensive Guide

    Oct 23, 2023 · The standard way to return a value from a method in Java is with the return keyword. For a String return, we define a method like: public static String getMessage() { return "Message returned via return statement"; } In the calling code, we can store the result: String msg = getMessage(); // Store return value. Some key advantages of using ...

  6. Java return Keyword - W3Schools

    The return keyword finishes the execution of a method, and can be used to return a value from a method. Tip: Use the void keyword to specify that a method should not have a return value: A method without any return values: Try it Yourself » Read more about methods in our Java Methods Tutorial. Java Keywords.

  7. Java return Keyword - GeeksforGeeks

    Jan 2, 2025 · return keyword in Java is a reserved keyword which is used to exit from a method, with or without a value. The usage of the return keyword can be categorized into two cases: 1. Methods Returning a Value. For the methods that define a return type, the return statement must be immediately followed by a return value. Example:

  8. Method to Take and Return String Data in Java - DZone

    May 1, 2020 · Is char[ ], String, StringBuffer, or StringBuilder the best way to take and return String data in Java? Take a look at this comparison.

  9. String (Java Platform SE 8 ) - Oracle Help Center

    Constructs a new String by decoding the specified subarray of bytes using the specified charset.

  10. Java Method Return String: Java Explained - Bito

    May 5, 2024 · Returning a string from a Java method is done via the return keyword. For example, if a method declared as “public static String someFunction(String x)” is designed to return a string, then the return keyword must be used with a String literal or String value.

Refresh