Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: hash map Date: Mon, 17 Apr 2017 10:15:08 -0400 Organization: A noiseless patient Spider Lines: 48 Message-ID: References: <9a86c6fb-ae40-4acd-902f-afff0ab60fd6@googlegroups.com> <208075f0-0022-4996-b2b7-a3b90f6c85a6@googlegroups.com> <25389b66-b30f-4076-8f8e-4bfeb91dbc6f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 17 Apr 2017 14:12:05 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="1c8b00ef01e12dbc4943e72d9f05af11"; logging-data="9500"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8gKxXrSq3K+E3XUmZRXMf" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:aZ+CQ3/lO2Q1JSZyvgO9fUP35Qg= Xref: csiph.com comp.lang.java.programmer:36463 On 4/17/2017 9:53 AM, pablo wrote: > > import java.util.*; > /** > * The class Garage is used to hold data about a collection of customers. > * > * @author M250 module team > * @version 1.0 > */ > public class Garage > { > //garage creating an empty instance of map map > private Map map = new HashMap(); Okay: This says that each "Garage" instance owns a Map whose keys are Strings and whose corresponding values are also Strings, and it arranges to create such a Map (empty) each time you create a Garage. Fine so far. > map.put("Andrew Smith, address 1 The High Street, area 1"); ... but this is, er, "less fine." For one thing, it's not a declaration but an executable statement, a call upon the Map's put() method. Executable statements can't just float around in the ether, but must be inside methods or constructors (or static blocks, but they are less common). After you've solved that problem by finding a suitable home for the executable statement, you'll discover another one: Map's put() method requires two arguments, the key and corresponding value of a key/value pair. The method call you have written provides only one argument, not the required two. Perhaps you meant something like map.put("Andrew Smith", "1 The High Street, area 1"); ... which associates the key "Andrew Smith" with the value "1 The High Street, area 1". That's just a guess, though, because we don't know what relationship this map is intended to represent. > > > } > -- esosman@comcast-dot-net.invalid Thirteen hundred seventy-four days to go.