exists

How to test for the existence of a key or value in a Scala Map

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is one of the shortest recipes, Recipe 11.21, “How to Test for the Existence of a Key or Value in a Scala Map”

Problem

You want to test whether a Scala Map contains a given key or value.

Solution

To test for the existence of a key in a Map, use the contains method:

Java ‘file exists’ testing

Java "file exists" FAQ: How can I test to see if a file or directory exists in Java?

Java File exists method

To test to see if a file or directory exists, use the "exists" method of the Java File class, as shown here:

File varTmpDir = new File("/var/tmp");
boolean exists = varTmpDir.exists();

The Java File exists method returns true if the file or directory exists, and false otherwise.

The Perl exists function - test to see if a hash key exists

Perl "hash key exists" FAQ: How can I test to see if a key exists in a Perl hash?

Many times when working with a Perl hash, you need to know if a certain key already exists in the hash. The Perl exists function lets you easily determine if a key already exists in the hash.

My Perl hash tutorials

Perl hash tutorials FAQ: Can you share some Perl hash tutorials, or Perl hash examples?

I've recently written a number of articles about the Perl hash construct (or "Perl array hash"). In an effort to try to organize the Perl hash tutorials I've written, I've created this article to help link them all together.

Perl: How to test if a file exists

Perl file exists FAQ: How can I perform a test to see if a file exists with Perl?

You can test to see if a file exists with the Perl "-e" file operator.

A Perl file exists example

Here's a short test/example:

Nagios error code 127, make sure your plugin actually exists

Nagios FAQ: I'm trying to get Nagios to work, but when it starts running there is an error message in the log file that says something like "Nagios, Error Code 127, Make sure the plugin you're trying to run actually exists". How I can fix this?

Java File IO: How to test whether a file or directory exists

Java File I/O FAQ: Using Java, how can you test to see if a file or directory exists?

Java test to see if a file or directory exists

Answer: Here's a sample Java method that shows this test. All you have to do is use the exists() method of the File class (java.io.File) to perform this test.