About 9,150,000 results
Open links in new tab
  1. Overriding toString() Method in Java - GeeksforGeeks

    Feb 25, 2022 · The toString() method in the Hashtable class in Java returns a string representation of the key-value mappings contained in the hashtable. The string is in the form of a comma-separated list of key-value pairs enclosed in curly braces.

  2. How to override toString() properly in Java? - Stack Overflow

    May 24, 2012 · @Override public String toString () { return new StringJoiner( // In Java 8 and later, StringJoiner is used to construct a sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.

  3. Overriding in Java - GeeksforGeeks

    Apr 22, 2025 · Overriding in Java occurs when a subclass or child class implements a method that is already defined in the superclass or base class. When a subclass provides its own version of a method that is already defined in its superclass, we call it method overriding.

  4. Override java string methods - Stack Overflow

    May 16, 2012 · but you can add extra functionality to String methods by using composition like below. this.str=str; return str.length()+1; You can't override final classes, of which String is one. You can, though, create your own class with String helper functions. e.g., public static String DoSomethingHelpfulToAString(String stringToDoStuffTo)

  5. Overriding and Using the .toString() Method in Java

    Nov 1, 2023 · We’ve overridden the toString() method to return the string representation of x. When we create an object myObj of MyClass and print it using System.out.println(myObj.toString());, it outputs ’10’. This is a basic way to use the toString () method in Java, but there’s much more to learn about it.

  6. java - Overriding toString method - Stack Overflow

    I am using .toString to return a string representation of an object, i.e. jcb.engineMove(move.toString()); will produce e2e4. What I am trying to do is to extract the text of this object (e2e4) as a string. After Googling I came across overriding the toString method so I came up with this:

  7. How to Override tostring () method in Java? - Tpoint Tech

    Sep 10, 2024 · Overriding the toString () method in Java is a simple but powerful way to provide a meaningful string representation of your objects. By following the best practices outlined in in this section, we had generated consistent string representations that are easy to read and comprehend in the code.

  8. Best Practices to Override toString Method in Java? - JavaBeat

    Oct 3, 2013 · In this article to we will see how to override the toString method and what are the best practices in Java. Java provides a default implementation for the method toString through a class java.lang.Object which is inherited by all Java classes .

  9. How to Properly Override the toString() Method in Java?

    Overriding the `toString()` method in Java allows you to provide a string representation of your objects. This can be particularly useful for debugging or logging purposes. Here's how to correctly implement the `toString()` method in your `Kid` class while addressing your constructor issues.

  10. How to Override the toString Method in Java - Delft Stack

    Feb 2, 2024 · In this tutorial, we will see how we can override the tostring() method in Java using an easy example to understand the concept better. Override the toString() Method Using the @Override Annotation in Java. The toString() method is a part of the Object class which is a superclass of every class in Java.

  11. Some results have been removed
Refresh