目录

protected abstract Object[][] getContents()

描述 (Description)

java.util.ListResourceBundle.getContents()方法返回一个数组,其中每个项都是Object数组中的一对对象。 每对中的第一个元素是键,它必须是String,第二个元素是与该键相关联的值

声明 (Declaration)

以下是java.util.ListResourceBundle.getContents()方法的声明

protected abstract Object[][] getContents()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回表示键值对的Object数组的数组。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.ListResourceBundle.getContents()方法的用法。

package com.iowiki;
import java.util.*;
// create a class that extends to ListResourceBundle
class MyResources extends ListResourceBundle {
   // get contents must be implemented
   protected Object[][] getContents() {
      return new Object[][] {
         {"hello", "Hello World!"},
         {"bye", "Goodbye World!"},
         {"goodnight", "Goodnight World!"}
      };
   }
}
public class ListResourceBundleDemo {
   public static void main(String[] args) {
      // create a new MyResources instance
      MyResources mr = new MyResources();
      // print the string for key hello
      System.out.println("" + mr.getString("hello"));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Hello World!
↑回到顶部↑
WIKI教程 @2018