![]() |
VOOZH | about |
In Java, the toString() method of the AbstractMap.SimpleEntry class is used to return a string representation of the key-value pair in the format key=value. If the key or value is null, it is represented as the string null. This method is used to provide a straightforward way to display the contents of the SimpleEntry object.
Example 1: Here, the toString() method of AbstraceMap.SimpleEntry class is used to print key-value pairs stored in a List.
0=100 1=200 2=300
Explanation: This example stores key-value pair in an ArrayList using AbstractMap.simpleEntry and print them using toString() method, which display the pais in key=value format.
public String toString()
Return Type: This method returns a string that represents the key-value pair in the SimpleEntry object.
Example 2: Here, the AbstractMap.SimpleEntry includes null as a key in its string representation when no key is provided.
null=Value
Explanation: In this example, we create a SimpleEntry object with a null key and a value "Value". The output is null=Value demonstrating that SimpleEntry includes null in its string representation.