Yesterday we took a look at Hashtable and ArrayList functionality with Java with Java Hashtable Primer Tutorial as shown below. Today we do this again but write the code within the Windows Visual Studio (2010 Express) IDE using VB.Net, using a Hashtable (VB.Net “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 VB.Net 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 (VB.Net) program we develop (and compile) today. The population of the ArrayList can sometimes proceed at the same time as the Hashtable, as we do with our code today.
The VB.Net code fits into a Visual Studio (2010 Express) VB.Net Console Application project. We use the InputBox method to handle the interactive input, and the output findings, as well.
Here is some downloadable VB.Net source code you could call Module1.vb 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, in VB.Net, today, with our tutorial. Hashtable and ArrayList concepts also exist in languages like Java and C#. Hope to see you again tomorrow.
Previous relevant Java Hashtable Primer Tutorial is shown below.
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
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.
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
We use another ArrayList
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.
If this was interesting you may be interested in this too.
23 Responses to VB.Net Hashtable Primer Tutorial