Rename hashtable keys

I need to rename some keys in an Hashtable, and i'm wondering if there are "better" ways than creating a new Hashtable and copying the values into it with different key names.

About using HashMap instead of Hashtable i'm not sure
i can do so, because i'm just modifying a part of a
huge web app and i'd need to make sure the change
doesn't affect other parts. Don't mess with it if you don't have to. I assumed (incorrectly) that this was a new program.
By the way what's the
advantage of HashMap over Hashtable ?HashMap isn't synchronized, and has some additional performance benefits over Hashtable. That doesn't mean that Hashtable is used when you need to synchronize the Map. The Collections class provides a method for that. The main reason is that Hashtable was replaced with HashMap. A new hashtable implementation was not created for no reason. There were problems with the original design. HashMap is a living class and will be updated and improved upon as needed. We can't say the same for Hashtable. The main reason Hashtable is still around is that it is used in too much code in the JDK and elsewhere. A lot of developers still use it and I think that's a huge mistake.

Similar Messages

  • Ignoring case in Hashtable key names

    Is there any way to check a Hashtable for a key value (which is a string) but to ignore the case of the letters in the string?
    if(hashtable.contains(keyValue)){ .... }
    returns false if the string keyValue has different capitalization from the key in the hashtable.
    Thanks
    J A

    No, if you want to do it by subclassing Hashtable (incidentally, why Hashtable rather than HashMap?) then you want to override the put, get, contains, and remove methods to call String.lowerCase() on the key. Sylvia's suggestion was to insert a wrapper around String into the map rather than to subclass the map.

  • Use of primitive datatypes as hashtable key finally OK?

    Are we finally at the point where we can use primitive values as keys in a hashtable? I know that this wouldn't work in the past, and I haven't needed to use a hashtable for years, so I haven't really cared.
    Yesterday I tried it in a program compiled for JVM 1.5, using ints for the keys, and it runs fine. Admittedly, I do get several "unchecked operation" warnings during compilation.

    Yesterday I tried it in a program compiled for JVM
    1.5, using ints for the keys, and it runs fine.
    Admittedly, I do get several "unchecked operation"
    warnings during compilation.It autoboxed the ints as Integers for you. Under the covers it is still using Integer objects.

  • Need to test for a Hashtable key in JSTL

    What I am trying to accomplish is to test a Hashtable for a specific key and if it is there run some HTML.
    This is my code but it obviously wrong since JSTL yells at me when I try to execute it.
    <c:set var="hash" scope="page" value="${UpdateStatusData}"/>
         <c:if test="${hash.containsKey('success')}">
              success
         </c:if>UpdateStatusData is a Hashtable. How can I modify this "code" in oder to test for a key?
    Thanks

    EL != java
    Luckily EL handles Maps quite well:
    <c:set var="hash" scope="page" value="${UpdateStatusData}"/>
    // one way
    <c:if test="${not empty hash.success}">
         success
    </c:if>
    // an alternative syntax
    <c:if test="${not empty hash['success']}">
         success
    </c:if>Cheers,
    evnafets

  • Renaming Foreign Keys in the Relational Model

    Hi,
    I'm new to Data Modeler, we are using v 3.0.0.66.5 and Oracle 11g, and I'm trying to build a Logical and Relational model for a new application.
    We always name our Primary Keys as ID, this is causing me a problem with my Foreign Keys names in the Relational Model, as they are showing as ID#. Is there a way to add the abbr. of the table to the Foreign Key?
    Thanks in Advance
    Sue

    I always do that job using Naming Standard Templates. This sequence renames ALL FK COLUMNS for ALL TABLES only in RELATIONAL MODEL:
    -Preferences > Data Modeler > Naming Standards > templates
    -into the box "Column Foreign Key"
    -Put something like that: {ref table}_{ref column}
    -Then, go into your modeler tree, select the relational model, right click and use "Apply Naming Standards to Keys and Constraints"
    -deselect all
    -select the last option "Column Foreign Key"
    -Go.
    What if the names still collide? What if you want to do the job for some--but-not-ALL tables? forget the method above. A transformation script will do that.
    You'll need some of these building blocks:
    - table.getFKAssociations()
    - keys.getRemoteTable().getAbbreviation()
    - column.setName()
    I'm novice to script coding, sorry I can't assemble a scripted solution right now.
    Edited by: T. on May 31, 2011 8:50 AM

  • HashTable keys() strange behaviour in JDK 1.3

    Hi,
    Has the behaviour of the keys()-method in HashTable changed from JDK 1.2.2 to JDK 1.3? I get this strange results:
    I have a hashtable, and asks it for an enumration of the keys using the keys()-method. In JDK 1.2.2 (in the debugger of the Visual Age IDE) this works fine and I'm able to go through the enumeration and use all the keys.
    However, when I run the same code in JDK 1.3, the enumeration returned does not contain all keys, and some keys are duplicated in the enumeration.
    I was able to circumvent this by getting a key Set (with the keySet()-method), ask the set for its Iterator, go through the Iterator and putting the keys in a Vector and finally asking the Vector for its elements as an enumeration.
    This way I got all the keys once, and it worked both in JDK 1.2.2 and in JDK 1.3.
    I think only one thread is accessing the HashTable at the same time.
    Have anyone experienced a similiar behaviour and/or knows the cause of it?
    Regards,
    Magnus Erkstam

    I've run into several cases where what passes for Java 1.2 in Visual Age for Java does not behave in accordance with the JLS, or does not behave the same as other versions of Java 1.2. In my case the differences came up with regard to method invocation. VA4J resolved what should've been ambiguous method invocations entirely based on the signature of the method.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=322726
    That thread talks about those problems, but also mentions an article I found which details diffences some researchers found between VA4J and several other compilers.
    http://www.cis.nctu.edu.tw/~wuuyang/papers/CTHPC2002ambiguities.pdf
    Wouldn't surprise me to hear there are ambiguities in the VA4J version of .equals() either.

  • Get a Hashtable key given a value

    hi,
    can anyone tell me how I get a the key of Hashtable value given the value. I cant see anything in the api, and having been trying to figure this out for hours.
    Hashtable numbers = new Hashtable();
    numbers.put("one", new Integer(1));
    numbers.put("two", new Integer(2));
    numbers.put("three", new Integer(3));
    if say I had value Integer 2, how can I find the key of this if I didn't know the key.

    I prefer HashMaps. You have to look for it yourself.import java.util.*;
    public class Test3 {
      public static void main(String[] args) {
        String[] data = {"Zero","One","Two","Three","Four","Five","Six"};
        HashMap hm = new HashMap();
        for (int i=0; i<data.length; i++) hm.put(data, new Integer(i));
    Random rand = new Random();
    Set keys = hm.keySet();
    for (int i=0; i<10; i++) {
    Integer value = new Integer(rand.nextInt(data.length));
    System.out.println("Looking for "+value);
    for (Iterator iter=keys.iterator(); iter.hasNext();) {
    Object key = iter.next();
    if (value.equals(hm.get(key))) {
    System.out.println(" Found key '"+key+"' with value '"+value+"'");
    }You might think about a reverse hashmap or else letting us know what you are trying to do.

  • Hashtable keys and enumeration

    Enumeration enumObj=hashAllDetails.keys();
    String strarray[]=null;
    while(enumObj.hasMoreElements())
    strarray[]=(String)enumObj.nextElement();
    for(int i=0;i<strarray.length();i++)
    System.out.println(strarray);
    hashAllDetails is hashtable.
    how can i get the keys of the hashtable into a string array. actually i have to compare each of the keys in the hashtable and check for single occurence.
    plz help me out.

    hi
    thanks a lot.
    i have to this too.
    Enumeration objEnumKeys = hashAllDetails.keys();
    while(objEnumKeys.hasMoreElements())
    String strHashKey = (String)objEnumKeys.nextElement();
    UserDetails objUserDetails = (UserDetails) hashAllDetails.get(strHashKey);
    System.out.println(objUserDetails.userid);
    i have the following code.
    in the hashtable hashAllDetails i have done this earlier
    hashAllDetails.put(keys,objUserDetails)
    UserDetails is a class with various fields. like userid, balance etc.
    now i need to get these userid values from the hashtable with are stored in the objects of UserDetails and need to compare values of userid field for single occurence.
    hope u can help me out. thanks..

  • Hashtable keys( ) question

    Hello guys,
    I have a question regarding hashtables.
    Here is a method which returns a vector that contains some items:
    public Vector getVectorItems()
            Vector oVector  = new Vector();
            Enumeration oEnum = coQueue.keys();
            while (oEnum.hasMoreElements())
                    oVector.add((String)oEnum.nextElement());
            return oVector;
    }My Question:
    There are times that when oVector is returned, it is empty.
    Up to now, I'm still wondering why is the vector was empty.
    Thank you very much for your help.

    You can use an Iterator instead ...
    public Vector getVectorItems() {
    Vector oVector = new Vector();
    Iterator iter = ((Set)coQueue.keySet()).iterator();
    while (iter.hasNext()) {
    oVector.add((String)iter.next());
    return oVector;
    Also, assuming coQueue is a HashMap, use the function KeySet() instead of keys().
    try it ....

  • Hashtable keys() deprecated

    Hi,
    i run my old 1.4.2 java with java 6 but i get a warning if i build my app:
    warning: [dep-ann] deprecated item is not annotated with @Deprecated
    Code:
    public Enumeration<String> getContentKeys() {
              return (htData.keys());
    htData is a hashtable, but i dont know what is deprecated??
    What is the Problem here?
    I have search the forum, but didn't found the solution, if there is a thrad, then plz link
    Greets ph0e

    You have a method with the "@deprecated" JavaDoc tag but without the @Deprecated annotation. The annotation was introduced in Java 5 and has pretty much the same purpose as the JavaDoc tag, but can be read at runtime.
    You should add the @Deprecated annotation to every place where you use the @deprecated JavaDoc tag, but if you don't then you won't have any major problems.

  • Match not functioning for hashtable keys

    Updated
    Hello,
    I'm seeing unexpected behavior and am hoping for a little help.
    My PS ver is:
    Major  Minor  Build  Revision
    3      8      0      129 
    Here is a snip that illustrates the issue (reproducible)
    $aRecords = $null; $aRecords = @{}
    $aRecords.add('tblARecords_1_txtHost','1.1.1.2')
    $aRecords.add('tblARecords_0_txtHost','1.1.1.1')
    $aRecords.add('tblARecords_1_txtPointsto','1.1.1.2')
    $aRecords.add('tblARecords_0_txtPointsto','1.1.1.1')
    $gdRecords = $null; $gdRecords = @{}
    $gdRecords['typeA'] = $aRecords
    $records = $null;$records = @()
    $records = 'tblARecords_0'
    foreach($g in $gdRecords.Keys) {
    foreach($d in $gdRecords[$g]) {
    if($d.Keys -match $records) {
    write $d
    $records = tblARecords_0
    But the results i get back are 
    tblARecords_1_txtHost
    tblARecords_0_txtHost
    tblARecords_1_txtPointsto
    tblARecords_0_txtPointsto
    Even if i substitute the the variablw $wr with the string itself ('tblARecords_0'). It still produces the same same results
    Any help would be appreciated

    I understand that he is devoting his own time and effort, and that he is not a MSFT employee. For that i am appreciative. My issue is that an approved moderator should be a bit more thoughtful with his language. Normally i wouldn't care but am having one
    of those days. Problem is someone may be put off from that approach and may not come back. Perhaps also move on to something else as a result.
    I also agree with his request, I probably should have made a reproducible script prior to posting and am updating my question.
    Sorry but I disagree.  I know you believe your post is useful and explains everything.  It doesn't.  None of us can decode your variables or comments because we do not have your environment or the full script.
    Bill was trying to point put that you need to put in more effort to ensure those who are trying to help you do not have to play guessing games.
    Items 7 and 8 are exactly to the point.  Addres those issues and you will likley get a quick and correct answer.
    Here are items 7 and 8:
    7. Let someone else devise a repro case. When the button click handler isn't called in your sample, by no means should you try to create a smaller repro case. All you know is that your sample doesn't run.
    8. Post a sample that depends on a resource you don't describe. Be sure your sample reads from your production database. Don't worry, people will figure out your schema.
    ¯\_(ツ)_/¯

  • Struts - example of iterate using a hashtable (key,value)

    I am trying to create a dynamic menu system and each menu group
    is storied within a single hashmap with the name of the menu as the key (e.g. "mainmenu", "adminmenu"). I am having problems understanding the documentation on how to pass the key to select the
    right entry within the hashmap. I have read the following but find
    it confusing. Could someone provide a detailed example?
    http://jakarta.apache.org/struts/struts-logic.html#iterate

    Here's some code to show you what I am doing.
    I will start out with how I am creating the List and the HashMap
        menuList = new ArrayList();
        sqlStatement = "select * from menu where admin = 'Y' ";
        // gets the menu items from the database and builds the menuList
        this.buildMenu( (DBResultSet)db.executeSQL( sqlStatement, args ) );
        // puts the menuList into a HashMap with a key of adminmenu
        //  NOTE: the menuList is actually a collection (list) of beans
        menuMap.setItem ("adminmenu", menuList );
        ...Here's my bean that stores I use to store the HashMap (menuMap).
    import java.util.*;
    public class MenuBO extends BaseBusinessObject
      private HashMap menuMap;
      public MenuBO()
        menuMap = new HashMap();
      public void setItem ( String menuType, List menuList )
        menuMap.put ( menuType, menuList);
      public List getItem( String menuType )
        return  (List)this.menuMap.get( menuType ) ;
      public HashMap getMenuMap ()
        return menuMap;
      public void removeItem ( String menuType)
        menuMap.remove( menuType);
    }And here's my iterate which is not working. I want to single out the value that has a key of "adminmenu" and process that list of menu elements. This is easy to do with scriptlets but I am spending many hours trying to figure out Struts documentation - they need some real world examples if they want Struts to catch on...
    <jsp:useBean id="menuMap" scope="session"
              class="com.benchdogs.webapp.beans.MenuBO"/>
            <logic:iterate id="mapEntry" name="menuMap" property="menuMap">
                <bean:write name="mapEntry" property="key"/>
            </logic:iterate>This example loops through the hashmap and displays the keys. I want to be able to process a specific value based on the key. The value is a List so I would need to do another iterate statement within the master iterate.

  • How can I get keys from Hashtable in the same order?

    Hello, everyone.
    I have a Hashtable containing key-value pairs, I need to get the keys in the same order as I use
    method put(key,value) to save the key-value pairs. But I can only find Hashtable.keys() to fetch the keys in form of Enumeration and when retrieve the keys from the Enumeration,they are not in the original order!
    The following is my code:
    Hashtable ht = new Hashtable();
    ht.put("Name","Harry Bott");
    ht.put("Gender","Male");
    ht.put("Age","25");
    String[] Items = new String[ht.size()];
    Enumeration e = ht.keys();
    int i = 0;
    while(e.hasMoreElements()) {
    Items[i++] =(String)(e.nextElement());
    The Items contains the keys but they are not in the original order.
    Does anyone know how to get the keys from a Hashtable in the same order when they're put?
    Thank you!

    yeah, another solution is to stored keys on a Collection at the same time you put them on the HashMap with its values.
    Then when ur going to retrieve objects from the Map u iterate the Collection that has the ordered keys and use them.

  • Connection object as a key in a hashtable

    Hi,
    I am debugging some code where a Connection object is used as a key in a hashtable. Is this ok? Will the equals() and hashCode method be defined properly for a Connection object?
    Appreciate your help.
    Thanks!

    I am debugging some code where a Connection object is
    used as a key in a hashtable. Is this ok? Will the
    equals() and hashCode method be defined properly for a
    Connection object?First, answer the following question for yourself: how do you defined equality of Connections?
    If a class merely inherits the equals() implementation from Object, then equality is the same as referential identity. If that is Ok for you [which is the case in surprisingly many cases], there is no harm is using Connections as hashtable keys.
    Vlad.

  • How can I use Automator to toggle the Function Keys?

    I am trying to create a Automated process to toggle the Function Keys on my keyboard. This is because I use several programs, including After Effects, which use the F1-12 keys, but when I am not using that program I commonly use the Apple-defined shortcuts on the keyboard. I have a full-sized keyboard, hence no Fn key. So that's out right away – I've read several comments on this topic where people suggested that this is the ONLY option. I refuse to beleive that.
    Automator contains a "Watch Me Do" feature, which I have tried to use to record this process. Problem is, it never clicks the right object. If I record clicking the dock, the magnification (I suspect) throws off the virtual-controlled mouse and picks the wrong object. If I record the Apple Menu route, it gets it about 1/2 the time.
    I think what I'm really looking for is a console command I can feed into the Terminal which toggles the keys. It seems to be that this HAS to be an option, even if it is more than one line of commands. I believe if I can feed this process into Automator, it would work.
    Any ideas?
    Thanks in advance, Mac Geniuses!

    iKey lets you define function keys per application. You seem to want to turn on & off the defined apple keys.  Not sure if these keyboard re-mappers will do the trick.
    Here is my other most favored application. Of course, I haven't checked these out in newer OS's. I'm a Tiger man myself.
    iKey is a front end program that simulates typing and mouse movements. I use iKey to remap the Function keys.
    "iKey is an automation utility, a program that creates shortcuts to accomplish repetitive tasks. In essence, an iKey shortcut is a little program in its own right, but you don't need to know the first thing about programming to create an iKey shortcut. All you have to do is put together three necessary parts of a shortcut: One or more commands that give the shortcut its functionality, a context in which it runs, and a launcher that defines how the shortcut is activated."
    http://www.scriptsoftware.com/ikey/
    iKey  has a little more function then the previous free version called youpi key. For many years, I used youpi key before switching to iKey.  It works fairly well for me in MAC OS 10.4 although not officially supported.  The youpi key download is hard to find & no longer here.
    http://www.versiontracker.com/dyn/moreinfo/macosx/11485&vid=75326
    ( Send me a message for a copy of youpi  key. )
    *Examples:*
    I have the common programs that I use assigned to function keys. I have F4 assigned to Firefox. When I want to start FireFox, I press F4. When I want to switch to firefox, I press F4! Starting & switching to an application in Mac OS are the same thing in Mac OS.
    Here is an example of to assign volumn control to a function key.
    http://discussions.apple.com/message.jspa?messageID=10361085#10361085
    Here is my script for listing my application folder. I have it assigned to function-key 6.
    tell application "Finder"
       open folder "Applications" of startup disk
       select Finder window 1
       set bounds of Finder window 1 to {-3, 44, 691, 545}
       --set position of Finder window 1 to {33, 44}
       set position of Finder window 1 to {60, 45}
       activate
    end tell
    The second portion of this script was generated in the script editor record mode. After I recorded the script and did some editing, I copy the script to ikey/youpi key.
    Full Key Codes
    http://download.cnet.com/Full-Key-Codes/3000-2094_4-44175.html
    Spark
    "Spark is a powerful, and easy Shortcuts manager. With Spark you can create Hot Keys to launch applications and documents, execute AppleScript, command iTunes, and more... You can also export and import your Hot Keys library, or save it in HTML format to print it. Spark is free, so use it without moderation!"
    http://www.versiontracker.com/dyn/moreinfo/macosx/22675
    Mac OS X remap or rename keyboard keys
    by vivek
    So how do you remap or rename keyboard keys under Mac OS X?
    Simply use DoubleCommand software.  It is a free program
    http://theos.in/apple/download-doublecommand-to-remap-keyboard-keys/
    Keyboard Maestro is a powerful macro program for Mac OS X (including Tiger and Leopard) which has received glowing reviews. Keyboard Maestro will take your Macintosh experience to a new level in “Ease of Use”. With Keyboard Maestro you can design a custom action sequence with your own shortcuts and use them at any time, you can navigate through running applications and open windows with Program Switcher, and you can work with an unlimited number of clipboards - all by pressing simple keystrokes.
    http://www.keyboardmaestro.com/main/
    "Spark is a powerful, and easy Shortcuts manager. With Spark you can create Hot Keys to launch applications and documents, execute AppleScript, command iTunes, and more... You can also export and import your Hot Keys library, or save it in HTML format to print it. Spark is free, so use it without moderation"
    http://www.versiontracker.com/dyn/moreinfo/macosx/22675

Maybe you are looking for

  • Bypass Logon screen of the SAP R/3 system where WDA application resides

    Hi, I created an application in WDA. I have another appplication in WDJ. On one of the views of WDJ application, I created a link to URL UI elem and provided WDA application's URL to it as a reference. When I click on the link to URL,  I expect that

  • Apps won't install, please help.

    I have an iMac which I use for my small business, for a particular software I had to fragment the disk and run Windows and after a few months I removed windows and now I have OSX 10.6.8. My problem is that the apps that I bought via my second iMac ar

  • Capturing sound samples

    hi , i need the best way to capture sound samples from an opened Microphone port is it by directly using a TargetDataLine and how ? and thanks

  • Crashing after Yosemite update!

    I've run into an issue with overheating crash in the past three days after I upgraded to Yosemite. this has never happened before. normal operations of the computer are fine. within 5 minutes of playing any kind of game the computer shuts off, which

  • Ipod can't play the song normally /sound problem.

    my new ipod have some problem with playing songs.( few minutes to sometime few hours ).the song will play like broken cd.but after i restart the ipod it will back to normal again.and again after sometime the song play abnormally..i restore the softwa