public boolean containsKey(Object key)
import java.util.Properties; public class Example { public static void main(String[] args) { Properties prop = new Properties(); prop.setProperty("name", "John"); prop.setProperty("age", "25"); if(prop.containsKey("name")) { System.out.println("The properties object contains the key 'name'"); } else { System.out.println("The properties object does not contain the key 'name'"); } if(prop.containsKey("gender")) { System.out.println("The properties object contains the key 'gender'"); } else { System.out.println("The properties object does not contain the key 'gender'"); } } }
The properties object contains the key 'name' The properties object does not contain the key 'gender'This example uses the java.util package library since it uses the Properties class from that package.