How would I search the hastable for homer?

This is an example that I did awhile back. I currently messing around with it just as a review. I got stuck on how I can implement a search for my hashtable. Here is what I have so far
import java.util.*;
public class SimpsonsClient {
    public static void main(String args[]) {
      Hashtable hash = new Hashtable();
      Student st1 = new Student("Homer", "Simpson", "0");
      Student st2 = new Student("Marge", "Simpson", "0");
      Student st3 = new Student("Bart", "Simpson", "0");
      Student st4 = new Student("Lisa", "Simpson", "0");
      Student st5 = new Student("Maggie", "Simpson", "0");
      System.out.println("Adding values to hash");
      hash.put(st1.getAge(), st1);
      hash.put(st2.getAge(), st2);
      hash.put(st3.getAge(), st3);
      hash.put(st4.getAge(), st4);
      hash.put(st4.getAge(), st5);
      System.out.println("Does the hash have st1?:" + hash.contains(st1));
      System.out.println("Is the hash code empty?" + hash.isEmpty());
      //Search for homer?
      System.out.println("Hash contain Homer?" + hash.get("Homer"));
    }Output Looks like this:
Adding values to hash
Does the hash have st1?:true
Is the hash code empty?false
Hash contain Homer?null
I just would like to know how I can do a search for homer and pull his records off like the name, age, and the field of 1.
Thanks

import java.util.*;
public class SimpsonsClient {
    public static void main(String args[]) {
      Hashtable hash = new Hashtable();
      Student st1 = new Student("Homer", "Simpson", "0");
      Student st2 = new Student("Marge", "Simpson", "0");
      Student st3 = new Student("Bart", "Simpson", "0");
      Student st4 = new Student("Lisa", "Simpson", "0");
      Student st5 = new Student("Maggie", "Simpson", "0");
      hash.put(st1.getAge(), st1);
      hash.put(st2.getAge(), st2);
      hash.put(st3.getAge(), st3);
      hash.put(st4.getAge(), st4);
      hash.put(st4.getAge(), st5);
    }I can't really tell actually. You haven't included a definition for the Student class. If it's something like this:
public class Student
  public String getName();
  public String getSurname();
  public String getValue(); // the third field
}In the old jdk 1.1 API
public static boolean tableContainsStudent(Hashtable table, String name)
  for(Enumeration students = table.elements(); students.hasMoreElements(); )
    if (((Student)students.nextElement()).getName().equals(name)) return true;
  return false;
}It's quite similar with Collections API
for (Iterator students=table.values().iterator();students.hasNext(); )
  if (((Student)students.nextElement()).getName().equals(name)) return true;
return false;
...I don't think the Hashtable is optimal at all for searching this way. It would be much nicer if you can do a binary search, but that requires more thinking when designing the storage class.
greets.

Similar Messages

  • How does one search the Store for IOS 4.21 only apps?

    Hi,
    I have FOUR iPod touch 2nd gens, with a max OS of IOS 4.21.   How do I search the Store for apps that will actually work on these devices?
    Thanks!

    iOSSearch - search the iTunes store for compatible apps.
    Vintapps 3.1.3 - paid app.
    Apple Club - filter apps by iOS version.

  • How do you change the user for Home Sharing on the Apple TV?

    I need to change the user on the Apple TV for Home Sharing but can't figure how or where to do it in the Apple TV settings. Can anyone help? Thank you.

    I bought my ATV at the Apple store Zurich Switzerland.  All the movies default to German. I hired a US movie and pressed and held the play/pause button once the movie had started but only the chapter menu displayed and there were no options to change the language (from the default German to English)
    Are all movies flagged on Swiss accounts only available in German? Is there a way of pointing my ATV to a different server.
    BR

  • How can I search the stage for a given Movieclip and then add all instances of it to an Array? AS3

    I would like to Add multible instances of one Movieclip, (Library Name = Bats | instance name = none), inside of another Movieclip (instance name = back.visuals) // (By HAND) NOT by addChild(mc_name); // Easy
    If anyone could help me out with code to do the next steps:
    Search the Movieclip, (instance name = back.visuals), that contains the Movieclips, (Library Name = Bats | instance name = none), manually added to the stage by hand.
    Then for all instances of this movieclip (Library Name = Bats | instance name = none) add them to an Array.
    Thank You,
    Dyami

    I think we are having some missed communication. I do not wish to Change Flash's IDE or deveolp new features for flash. I was wondering if there was a way to do my question with AS3. something along the lines of :
    var enemyList:Array = new Array;
    for (var index:int = 0;index < back.visuals.numChildren;index++)
        var wall:MovieClip = back.visuals.getChildAt(index) as MovieClip;
    /* Check to see if wall is of a Specfic MovieClip */
    /* if (Above is True){ enemyList.push(wall) };

  • How can I search the forum for the questions that I have asked in the past. Sorry, this may be a stupid question but I am new here

    Just was asking how do I browse through the forum, here, to see my questions and answers and other question and answers.
    Thanks

    https://support.mozilla.org/en-US/search?a=1&asked_by=gifropan&sortby=1&w=2
    Click on your username under your avatar in this thread. <br />
    https://support.mozilla.org/en-US/user/834634 <br />
    Then click on the "2 questions" hyperlink under '''Contributions''' on that page.
    You can also acces that page via your username at the top of the first "answers" page, under "View Profile".

  • How do I search a spreadsheet for a list of URL's | then search those URL's for keywords | save the output? (Oh yeah..., and schedule it)

    Fist, I should mention I am not a programmer but am eagerly learning powershell!
    I am looking for an automated solution to accomplish what I am currently doing manually.  I need a script that would combine the following:
    Reach out to a list of websites (probably a loop of some sort since the list will come out of a spreadsheet which could contain 1 or 100 different sites)
    Search each page for a specific word or words (not contained in the spreadsheet though that may make it more scalable)
    Save the URL of the site(s) that contained the keywords to one text file (versus the multiple .html files I am creating today)
    Have the output contain which words it found on which site.
    If not overly complicated, I would like to schedule this to recur once a week.
    A working script would be ideal, but even the resources that show me how to incorporate each element would suffice.
    I have had success pulling down the full content of the listed pages and saving them to a directory, which requires manual intervention.
    So far this works, but it's not scalable:
         Set-ExecutionPolicy RemoteSigned
         $web = New-Object Net.WebClient
         $web.DownloadString("http://sosomesite/54321.com") | Out-File "C:\savestuffhere\54321.html"
         $web.DownloadString("http://sosomesite/54321.com") | Out-File "C:\savestuffhere\65432.html"
         Get-ChildItem -Path "C:\savestuffhere\" -Include *.html -Recurse | Select-String -Pattern "Keyword 1"
    In otherwords, I have to manually replace the "http://sosomesite/54321.com" and "C:\savestuffhere\54321.html" when the URL changes to .\65432.com and the output name to match.  That works fine when it's a couple sites, but again,
    is not scalable.  
    Then, to see if any of the saved file's contain the keyword(s), I have to search the directory for the keyword which I am using:
    Get-ChildItem -Path "C:\savestuffhere\54321.html" -Include *.html -Recurse | Select-String -Pattern "Keyword 1"

    Hi Sure-man,
    Sorry for the delay reply.
    To automatically Reach out to all urls, you can list all urls in a txt file "d:\urls.txt" like this:
    http://sosomesite/54321.com
    http://sosomesite/65432.com
    Then please try the script below to save the URL of the site(s) that contained the keywords to one text file "d:\outputurls.txt":
    $urls = get-content d:\urls.txt
    foreach($url in $urls){
    $results = $web.DownloadString("$url")
    $matches = $results | Select-String -Pattern "keyword1","keyword2"
    #Extract the text of the messages, which are contained in segments that look like keyword1 or keyword2.
    if ($matches.Matches){
    $Object = New-Object PSObject
    $Object | add-member Noteproperty keyword $matches.Matches.value
    $Object | add-member Noteproperty URL $url
    $output+=$Object}
    $output|Out-File d:\outputurls.txt
    If you want to schduled this script in Task Scheduler once a week, please save the script above as .ps1 file, and follow this article:
    Weekend Scripter: Use the Windows Task Scheduler to Run a Windows PowerShell Script
    If I have any misunderstanding, please let me know.
    I hope this helps.

  • I HAVE AN IPHONE 5S AND WANT TO USE SOFTWARE 7.0.2 BECAUSE IT IS COMPATIBLE WITH MY VEHICLE FOR UCONNECT. I CURRENTLY HAVE SOFTWARE 7.0.3 ON MY DEVICE. HOW WOULD I GET THE PREVIOUS SOFTWARE BACK ON MY PHONE

    I HAVE AN IPHONE 5S AND WANT TO USE SOFTWARE 7.0.2 BECAUSE IT IS COMPATIBLE WITH MY VEHICLE FOR UCONNECT. I CURRENTLY HAVE SOFTWARE 7.0.3 ON MY DEVICE. HOW WOULD I GET THE PREVIOUS SOFTWARE BACK ON MY PHONE

    Forum Tip: It is generally considered inappropriate to type all in uppercase letters in Internet discussions, as text that is typed all in uppercase is by convention considered to be shouting.  Uppercase is also more difficult to read, so please use all uppercase sparingly and only when you really mean to shout, which we hope you won’t need to do here .
    Regards.

  • Can I set up a new Mac Pro late 2013 using a Wacom Cintique 13HD tablet as the default monitor? How would I install the driver software for the tablet?

    Can I set up a new Mac Pro late 2013 using a Wacom Cintique 13HD tablet as the default monitor? How would I install the driver software for the tablet?

    The wacom site will have the drivers for you.
    http://us.wacom.com/en/support/drivers

  • HT202213 The screen displayed on the instructions for home sharing described as being found on the left side of iTunes isn't visible on the new iTunes page?? Where do i find that screen i.e., how do I fine the home sharing icon on the new iTunes page?

    The screen displayed on the instructions for home sharing described as being found on the left side of iTunes isn't visible on the new iTunes page?? Where do i find that screen i.e., how do I fine the home sharing icon on the new iTunes page?

    ontthe top menu
    View > Show sidebar
    Then the computers for home sharing show up under the Shared section

  • How do I restore the settings for apps using Time Machine?

    I believe there are problems with items within the Library Folder inside the System Folder.  For example, there are two "Frameworks" Folders, but one has "(from old Mac)" after its name.  I dare not try to remove or even move either.
    Back in the day of OS 9, you could modify something, then search for it by "Last Modified" Date, and find where Apple has hidden itscontents.  It's not so easy in OS X.  I've had some success using Pondini's Time Machine FAQ's, though.  Here is how I got to this problem:
    Our family MacBook died.  After getting a repair estimate of $500 to $700 "if it's the Logic Board," we decided to replace it.  We purchased a MacBook Pro running Lion.  (Later, we brought it to an Apple Store and were quoted $435 in house or $280, but they would have to send it out.  Incredible repair: Logic Board, Top & Bottom Case, Super Drive, Battery, all for $280.  No wonder they're #1).  I pulled the Hard Dive out, erased it, and installed an older operating system, but during the repair they installed 10.6.
    Restored the MBP from the TM backup of the MacBook. OK
    The Macbook is repaired and the store showed me how to restore the data from the TM backup.
    Restart and the passwords do not work due to restoring a 10.6 machine from a 10.7 backup.
    Tech support guides me through resetting an admin password using the password utility on the install DVD.
    changed the other passwords inside of Accounts in System Preferences.  Then changed the password or the other Admin.
    Restart, get a circle with a line through it.
    Tech support guides me through fixing this.
    Restart, half my Apps do not work.
    Tech support says to re-install 10.6.
    I did but I thought it would erase and install but it just re-installed 10.6.
    Most Apps work, except iPhoto.  Mail is OK sending but only receives on one of 3 accounts.
    Is there a fix for iPhoto & Mail?  If not, I would plan to erase and use the finder to drag the user folders from TM to the MacBook.  Can I just drag the Apps too?  How about all of the settings for those Apps?

    If you don't keep a backup, you can't restore your machine to any state except the state in which you received it, brand new, with none of your own stuff on it. That makes a pretty convincing argument for backing up, doesn't it?

  • How can I decouple the pagination for a global region?

    I was having a delightful time using a common region defined on a global page when I determined that pagination setting was begin carried from one page to the next.  Arghhhh!  So for example, if I have paged to the second set (page) of rows (11-20) on Page 1 and then I go to Page 2, the second set (page) of rows (11-20) is displayed there.   If I go to a page which only has a first set of rows (1-10), I get the pagination error "Invalid set of rows requested, the source data of the report has been modified. Reset Pagination".  And when I click to reset, it just repeats the error.  [I suppose it tries to display the second set or rows (11-20) again -- which doesn't exist.  What's that saying about insanity?]  
    How can I decouple the pagination for a global region? I want it to operarate just as it would if it were not sharing a common region.  So if I'm looking at rows (11-20) on page 1, I can go to any other page beginning with rows 1-10 there.  Then return to page 1 where I left off with rows 11-20 displayed.  One solution is NOT to paginate but that's not my preferred solution.
    Howard

    Howard(...inTraining) wrote:
    I was having a delightful time using a common region defined on a global page when I determined that pagination setting was begin carried from one page to the next.  Arghhhh!  So for example, if I have paged to the second set (page) of rows (11-20) on Page 1 and then I go to Page 2, the second set (page) of rows (11-20) is displayed there.   If I go to a page which only has a first set of rows (1-10), I get the pagination error "Invalid set of rows requested, the source data of the report has been modified. Reset Pagination".
    The fact that there are different numbers of rows returned on different pages implies that the reports have some local page dependencies, so why try to use a global component? What's the actual requirement? How many pages does the report have to appear on? (Please say it is a report and not a tabular form...)
    How can I decouple the pagination for a global region? I want it to operarate just as it would if it were not sharing a common region.
    The point is that a global region is just that: a single region that happens to be displayed on multiple pages. It does not create multiple instances of a region on different pages. (Specifically, a region has a single region ID, and this is used to reference it whether it appears on one page or all of them. The region ID is used by the report for the purposes of AJAX refresh, pagination etc.)
    A similar situation was discussed a long time ago. I'm rather surprised that Scott regarded it as a bug: the fact that it doesn't seem to have been "fixed" or have a bug number attached may indicate that the others on the APEX team disagreed with him? I haven't tried the workaround he suggested, however I don't think it's likely to be prove a useful line of attack for your issue, as (1) it resets pagination rather than preserving it; and (2) it doesn't appear to be compatible with the AJAX PPR pagination used in more recent versions of APEX.
    I can't see any straightforward "solution" (largely because I don't think there's really a problem: the exhibited behaviour is exactly how I expect/want global regions to behave). Pagination processing is undocumented. The current 4.2 apex.widget.report.paginate JS method is specifically annotated as "for internal use only". Search the forum for custom pagination techniques. Messy looking hacks for IRs have previously been suggested.
    So if I'm looking at rows (11-20) on page 1, I can go to any other page beginning with rows 1-10 there.  Then return to page 1 where I left off with rows 11-20 displayed.  One solution is NOT to paginate but that's not my preferred solution.
    Assuming that there aren't too many pages involved, the other obvious option is to create unique regions on the required pages. You can achieve some level of reusability by creating SQL Query (PL/SQL function body returning SQL query) reports based on an external function so that there's only a single SQL source to be maintained.
    Explain the requirement in more detail. Pagination is not the only option for reducing the quantity of displayed information. Often it's better to display some of all of the data, rather than all of some of it...

  • How can I disable the Keychain for an application?

    How can I disable the Keychain for an application? A window pops up every time I open a page in Safari asking me for a password. I'm using a student laptop, so while I'm an administrator I lack access to a few things, such as the Keychain Access application. Is there any way to deal with this?

    It's possible you may be able to trick it by creating an Applications folder in your Home directory and moving Safari to it.
    I can't test this but it might work. The problem is that you would miss Safari updates, so you'd have to keep an eye out for them. Another solution may be to download another Safari and install in yourname/Applications.

  • How do I change the script for a voice iChat Alerts for when a friend becomes unavailable?

    How do I change the script for a voice iChat Alert for when a friend becomes unavailable?
    Before I upgraded my system from Mac OS 10.4.11 to Mac OS 10.6.8 - I a had personalized the script for a voice iChat Alert when my husband logged off from work. I had the ichat voice warn me "OH, Crap! he's coming home now! Hurry clean house!" This personalized voice alert did not survive the upgrade. Now, I need step by step instructions to walk me through the process. Please help! I mis my machine shouting funny profane alerts.

    Hi,
    In iChat 3 (OS 10.4.x) there was  Line at the Bottom of iChat > Preferences > Alerts that you could enter text to and it would speak that Text.
    (you could set something against Individual Buddies as well).
    This Setting is not there in iChat 4 or 5  (I presume iChat 6 as well).
    Now it is possible to write AppleScripts that can Speak.
    It is alos possible in iChat 4 upwards to link an AppleScript to an Action/Alert
    At this point my lack of AppleScript knowledge lets me down on what to tell you to do next.
    An Alternative would be to Record a sound with said alert.
    Place this sound in your Home Folder/Library/Sounds
    Then in the Alert opton for youe husband select the Log off option and link that Sound
    <
    10:25 PM      Wednesday; August 3, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.8),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Is there a way to get lightroom to search the computer for catalogs like aperture does?

    Is there a way to get lightroom to search the computer for catalogs like aperture does? I've switched over from Aperture to Lightroom, and i liked how in Aperture when i went to open "other library" it would basically scan all connected drives for them, and show me when last opened and what version. Is there a way to do this with Lightroom, either in program or by a third party app?

    The user interface is on a level of elementary PC software
    something I have deteced till now
    no free moving workspace windows
    no search function for the whole catalog
    no support of mpg files in the archive
    no chromatic appararture correction
    second screen sometimes gets lost, when moving between screens
    no automatic creation of collection ( very risky direct interfacing with the original file system )
    wrong counting of objects in catalog folder when creating virtuel copies
    What worked good is the import of the APERTURE Archive ( 40000 objects ) took me one night and its there with the above obsticles!!! I am using just three days and I have to say
    not user friendly
    not workflow supporting
    risky user interfacing with masters
    As JimHess stated, there is no risk working with the masters.
    Chromatic aberation correction is available in Lightroom, searching the entire catalog is available in Lightroom.
    With regards to your other comments, the idea that Lightroom should work the same (or very similar) to Aperture is one that you should remove from your thoughts. It will only get you into trouble. Lightroom is not Aperture and will not work the same, and has different underlying principles, and so its pointless to think you will be able to do everything the same way you did it in Aperture. You need to be open to Lightroom's features, and Lightroom's way of doing things. I agree with JimHess that it takes most people a while to learn Lightroom's way of doing things, but your patience will be rewarded.

  • How do i search a textfile for a particular value?

    How do i search a textfile for a particular value?
    I have made the records etc, six fields per record, i would like to find a value which is typed into the search textbox, find the record in the textfile and display the record in the boxes used to enter the data.
    SO HOW WOULD I SEARCH A TEXTFILE?
    Thanks very much for your help, Antony (UK)...

    If it were me, I'd use Lucene. Each line could be a separate document, and each field would be a field in Lucene. That would provide you one of the fastest and most flexible ways to do what you want.
    Or did you mean you want someone to complete your homework assignment? :-)

Maybe you are looking for