Home » Java programming language

Java ListResourceBundle getContents() Method with Example

ListResourceBundle Class getContents() method: Here, we are going to learn about the getContents() method of ListResourceBundle Class with its syntax and example.
Submitted by Preeti Jain, on March 22, 2020

ListResourceBundle Class getContents() method

  • getContents() method is available in java.util package.
  • getContents() method is used to get the contents into the form of an Object array (Object [][]) and every item is pairs of objects in an Object[][] where first indices represent the key element and the second indices represent the value element linked with the key in an object array.
  • getContents() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getContents() method does not throw an exception at the time of getting contents.

Syntax:

    protected abstract Object[][] getContents();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Object [] [], it returns 2D object array that contains two objects in the form of key-value pairs.

Example:

// Java program to demonstrate the example 
// of Object[][] getContents()  method of  
// ListResourceBundle 

import java.util.*;

// Instantiates a class that extends
// ListResourceBundle 
class GetContents extends ListResourceBundle {
 // By using getContent() method is to
 // get the contents in the form of 
 // 2D objects
 protected Object[][] getContents() {
  return new Object[][] {
   {
    "10",
    "C"
   }, {
    "20",
    "C++"
   }, {
    "30",
    "JAVA"
   }, {
    "40",
    "SFDC"
   }, {
    "50",
    "PHP"
   }
  };
 }
}

public class Main {
 public static void main(String[] args) {
  // Instantiates an object of
  // GetContents
  GetContents get_c = new GetContents();

  // Display the value for the 
  // given key element
  System.out.println("get_c.getString(40): " + get_c.getString("40"));
 }
}

Output

get_c.getString(40): SFDC






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.