I’m new to Java, and need to know how to pass an associative array (Map) as a single parameter in a function.
Here’s what I’m wanting to do in Java, shown in PHP.
<?php
public class exampleClass {
public function exampleFunction($exampleParam){
if(isset($exampleParam['exampleKey'])){
return true;
}
else {
return false;
}
}
}
$ourMap = array(
'exampleKey' => "yes, it is set"
);
$ourClass = new exampleClass();
$ourResult = $ourClass->exampleFunction($ourMap);
if(!$ourResult){
echo "In Map";
}
else {
echo "Not in Map";
}
?>
Where
Kis the type of the keys, andVis the type of the values.Note that
Mapis only an interface, so to create such a map, you’ll need to create an instance ofHashMapor similar, like so:See also: