Java Hashtable Primer Tutorial

Java Hashtable Primer Tutorial

Java Hashtable Primer Tutorial

Some time ago (with Java XCode ArrayList Primer Tutorial as shown below) we used a (Java “collection”) data structure called ArrayList in Java via Xcode on a Mac laptop. Today we do this again (without the Xcode these days), but also use a Hashtable (Java “collection”) data structure, to create a simple Contact List program. Are you familiar with Hashtables? They can simulate, in a lot of ways, what a relational database can do for you to use a Java collection to address that “age old” programming logic “sentence” …


hashtable["key"] = "value"

… do you see how like a database (table design) that statement is? And also how like the way a lot of us think, that is? Also close in thought to this are associative arrays.

The combination of ArrayLists and Hashtables add many possibilities for sorting ideas for our Contact List (Java) program we develop (and compile) today. The population of the ArrayList can sometimes proceed at the same time as the Hashtable, as we (mostly) do with our code today (making use of the interactive (console) Scanner class), but we also populate an ArrayList after the (populating) event for the reverse Enumeration part of the data, and this may interest you … look for …


for (Enumeration e = contactsHT.elements(); e.hasMoreElements();) {
sortingEmail.add(e.nextElement());
}

The compilation instructions are very simple for a Terminal command line session on a Mac laptop (but could equally apply for other platforms too) …

  • javac TestHashtableArraylist.java
  • java TestHashtableArraylist

…. though there is functionality to accept extra command line arguments to specify a name of interest that you want to find the email of during the normal execution of the program.

Here is some downloadable Java source code you could call TestHashtableArraylist.java and you can get a close up of the tutorial picture.

Hope you get some ideas out of Hashtables and ArrayLists and the combination of the two, perhaps, in Java, today, with our tutorial. Hashtable and ArrayList concepts also exist in languages like VB.Net and C#. Hope to see you again soon.


Previous relevant Java XCode ArrayList Primer Tutorial is shown below.

Java XCode ArrayList Primer Tutorial

Java XCode ArrayList Primer Tutorial

Here is a tutorial that uses ArrayList structure in Java via XCode on a Mac laptop.

This program counts the occurrence of characters within the contents of a text file.

We have one input text file which we are going to read.
We use one ArrayList to contain characters of interest to find.
We use another ArrayList to contain character counts collected.

Breaking this down, it would be good to:

a) have method that reads the text file and does the report
b) have method to count occurrences of a character within a String
c) have method to count number of words within a String (and total characters in words)

This way you can report:

. occurrences of a character of interest within a line of the input text file
. total count and percentage of characters of interest within the whole text file
. total count and percentage of other characters within the whole text file
. total count of words within the whole text file
. average word size is ((total characters in words) / (total count of words))

So we’ll build up a FindOccurrences class this way.

Need to have rules about the input text file. Will have it that:

1) there is an optional first header record with number of records of interest
2) all records need {cr} (and/or {lf}) delimitation (as a text file should)

How do we obtain the filename? Will have it that:

(1) it can optionally be passed as a command line parameter
(2) if not we will prompt for it and allow a non-answer meaning it is inputfile.txt

Do we assume a and A (for instance) are the same thing? Will have it that:

(a) assume as a default a and A are to be treated as one entity for searching purposes
(b) there is a, albeit awkward, way to say that a and A are separate, via (2) above

Let’s see some Java programming code for this, and how it works …

Download source code and rename to FindOccurrences.java

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Operating System, Software, Tutorials and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

10 Responses to Java Hashtable Primer Tutorial

  1. Whoa. That was a fantastic report. Please keep writing since I really like your style.

  2. You produced some decent points there. I looked online towards the problem and discovered most people is going in addition to using your site.

  3. jobs for history majors says:

    Iโ€™m a blog crazed person and i appreciate to read cool blog like yoursโ€ฆ;*:

    http://angalcupper.blog.com/2016/03/29/what-are-you-able-to-do-having-a-history-degree/

  4. Diani Beach says:

    Iโ€™m impressed, I will have to say. Incredibly rarely do I encounter a website thatโ€™s each informative and entertaining, and let me let you know, you have hit the nail on the head. Your blog is important, the challenge is something that not enough individuals are speaking intelligently about

    http://babayroy.blogspot.in/2016/04/choosing-right-kenya-safaris.html

  5. feature says:

    My personal web searches seem total.. thanks. Seriously advantageous viewpoint, thanks for giving.. Take pleasure in the entry you supplied.. Wonderful thoughts you’ve got here..

  6. Full Report says:

    My personal browsing efforts seem total.. thank you. So happy to possess located this post.. Great beliefs you’ve got here.. Excellent feelings you have here..

  7. enthusiastic says:

    Good info and right to the point. I don’t know if this is truly the best place to ask but do you people have any ideea where to employ some professional writers? Thx :)

  8. original templates, many of them free of charge for download at http://scarab13.com.

  9. Folks, I just downloaded some amazing freebies from http://scarab13.com. There are some very cool creative resources, all done exclusivelly by Scarab13, a popular name in creative world for goodness of mankind.

  10. My brother recommended I might like this blog.
    He was totally right. This put up actually made my
    day. You can not consider simply how so much time I had spent for this
    information! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>