Java Utility Library

Java Properties - list() Method



The java.util.Properties.list() method is used to print this property list out to the specified output stream. This method is useful for debugging.

Syntax

public void list(PrintWriter out)

Parameters

out Specify an output stream.

Return Value

void type.

Exception

Throws ClassCastException, if any key in this property list is not a string.

Example:

In the example below, the java.util.Properties.list() method is used to print the given property list out to the specified output stream.

import java.util.*;
import java.io.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Properties
    Properties Prop = new Properties();

    //creating a PrintWriter object
    PrintWriter Writer = new PrintWriter(System.out);

    //adding some values
    Prop.put("Blue", "10");
    Prop.put("Red", "20");
    Prop.put("Green", "30");

    //printing the list with a PrintWriter object
    Prop.list(Writer);

    //flush the stream
    Writer.flush();
  }
}

The output of the above code will be:

-- listing properties --
Green=30
Red=20
Blue=10

❮ Java.util - Properties