Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36452

Re: hash map

Newsgroups comp.lang.java.programmer
Date 2017-04-17 04:31 -0700
References <9a86c6fb-ae40-4acd-902f-afff0ab60fd6@googlegroups.com> <od0mla$15dm$1@gioia.aioe.org>
Message-ID <e7980823-ffc0-4905-836d-ac1dcf01d2e3@googlegroups.com> (permalink)
Subject Re: hash map
From pablo <pa24959122@gmail.com>

Show all headers | View raw


On Sunday, 16 April 2017 22:11:16 UTC+1, omegajunior  wrote:
> pablo <pa24959122@gmail.com> Wrote in message:
> > hi all i am trying to add to a hash map but i cant seem to do it could somebody look at the code and tell me why the hell i cant add the key and value 
> > 
> > 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<String,Customer> Customer = new HashMap<String, Customer>();
> >    
> > 
> >    public Garage() 
> >    {
> >      Customer = new HashMap<>(); 
> >    }
> >    
> >    public void addCustomer(String Customer)
> >    {"
> >       Customer.Put(Andrew Smith, address 1 The High Street", area 1, "123ABC");
> > }  
> > 
> 
> 1. You seem to have got your structures wrong. What you're adding
>  to the Customer map is <Name, Address>, but instead of Address
>  you've defined Customer to contain Customer. If that doesn't
>  confuse you, I applaud your mental prowess. 
>   
> 2. Your code doesn't put a String and an Address into the map.
>  That's because your code doesn't wrap the customer's name in
>  quotes. Leaving out the quotes makes Java interpret the name as a
>  Java language keyword or a class or variabla name, which probably
>  isn't your intent. 
>   
> 3. Your code uses a Map#Put method. The Map class doesn't have a
>  method named Put. It's named put. Note the lower-cased
>  p.
>   
> Combining that, this should work: 
>   
> final class mine {
> 
> private final map<String, String> customers = new HashMap<>(); 
> 
> public final void add() {
>   this.customers.put("Andrew Smith", "1 The High Street, area 1,
>  123ABC");
> }
> 
> }
> 
> If you want the customers map to hold an Address type rather than
>  a String containing address data, you'll have to define an
>  Address class, first.
>   
> Does that help?
> -- 
> We make software better.
> 
> 
> ----Android NewsGroup Reader----
> http://usenet.sinaapp.com/

not really i am trying to add a key this will be a string and the customer will be the value of the data i want to store in the hash map 

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

hash map pablo <pa24959122@gmail.com> - 2017-04-16 11:53 -0700
  Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-16 19:10 +0000
  Re:hash map omegajunior <omegajunior@protonmail.com> - 2017-04-16 17:11 -0400
    Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 04:31 -0700
  Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 05:11 -0700
    Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 05:32 -0700
      Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 05:58 -0700
      Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 09:10 -0400
        Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 06:53 -0700
          Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 10:15 -0400
            Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 07:25 -0700
              Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 07:46 -0700
              Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 10:54 -0400
                Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 08:29 -0700
                Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-17 08:44 -0700
                Re: hash map Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-04-17 12:07 -0400
                Re: hash map pablo <pa24959122@gmail.com> - 2017-04-17 09:32 -0700
                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-17 23:14 +0000
                Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-17 20:22 -0400
                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-18 01:20 +0000
                Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:01 -0400
                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-19 09:02 +0000
                Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-18 04:54 -0700
                Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:03 -0400
                Re: hash map Martin Gregorie <martin@address-in-sig.invalid> - 2017-04-19 08:55 +0000
                Re: hash map Eric Douglas <e.d.programmer@gmail.com> - 2017-04-19 04:45 -0700
                Re: hash map Arne Vajhøj <arne@vajhoej.dk> - 2017-04-18 20:05 -0400

csiph-web