温馨提示×

Java DataDictionaryEntry类使用实例

小亿
74
2023-12-19 02:19:54
栏目: 编程语言

以下是一个使用Java DataDictionaryEntry类的示例:

public class DataDictionaryEntry {
    private String key;
    private String value;

    public DataDictionaryEntry(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static void main(String[] args) {
        DataDictionaryEntry entry = new DataDictionaryEntry("name", "John");
        System.out.println("Key: " + entry.getKey());
        System.out.println("Value: " + entry.getValue());

        entry.setKey("age");
        entry.setValue("25");
        System.out.println("Key: " + entry.getKey());
        System.out.println("Value: " + entry.getValue());
    }
}

在上面的示例中,我们定义了一个DataDictionaryEntry类,该类具有keyvalue两个属性,以及相应的getter和setter方法。

在main方法中,我们创建了一个DataDictionaryEntry对象entry,并通过构造函数将键值对"name"和"John"传递给它。我们使用getKeygetValue方法来获取键和值,并打印它们的值。

然后,我们使用setKeysetValue方法来更改键和值为"age"和"25",并再次打印它们的值。

输出结果将是:

Key: name
Value: John
Key: age
Value: 25

0