Adding object to hashtable

If I add an object to a hash table ....
put(keyX, ObjectX)
and then add the SAME object again but with a different key....
put(keyY, ObjectX)
Do I end up with two elements in the hashTable?

yup.. with 2 exact object just different keys...

Similar Messages

  • Error Adding object to collection

    Hi all... I'm using Toplink + ADF Faces...
    We have the following problem: There are 2 tables involved, table A and table B
    Table B has a FK to table A, therefore a one-to-one mapping from B to A and a one to many mapping (collection) from A to B.
    What I want to do is to add an object of type B to the collection of an A object. I'm showing an input form for the constructor of type B, a submit button, and a read only table bellow to show the items of the collection. I have done this several times and worked fine, now I have NO clue why this is not working.
    What I used to do to achieve this is to call the method of the type A "addB(B)" (to add the object) and then the "Execute" operation (to refresh the table shown) of the collection in which the addB method is adding objects.
    What I get is just:
    2006-11-17 13:53:30.421 WARNING JBO-29000: Unexpected exception caught: java.lang.NullPointerException, msg=null
    2006-11-17 13:53:30.421 WARNING java.lang.NullPointerException
    and no more details.... :-S
    Does anyone know why this could be happening???
    or
    Is there some other way of adding objects to a collection using ADF and toplink?? Any suggestion is more than welcome!! I've been trying for too long to solve this... :-(
    Thanks in advance

    Here is another symptom:
    a few days ago, I developed a search page of objects of type "C". This type, has a collection of objects of type "B". This page is working fine, now... I do exactly the same steps to create a new page with the same search functionallity, and I get the same NullPointerException described above (with no extra information).
    Since the development of that working page until now, I manually added the mapping of table "A", which was not mapped by the time we developed the working search page. So I guess something is wrong with this new mapping.
    Here are the steps i did to map the new table "A" and define the relationship with table B (through a foreing key defined in DB):
    - created Java objects from tables for table "A".
    - added a FK from "B"->"A" in table "B" in the Offline Database Sources (just like the FK in the real DB)
    - added a ValueHolder attribute to class "B" (with the appropiate get and set, and initializing it in the constructor of class "B")
    - added a List attribute in class "A" of objects of type "B" (with the appropiates add, remove, get and set methods), and initializing the List as a new ArrayList in the constructor.
    - in the toplink map, mapped the new attributes:
    one-to-one for the Valueholder in class "B" (using the appropiate FK)
    one-to-many for the List attributes in class "A" (using the appropiate FK)
    - refreshed all possible datacontrol
    And thats it... am I doing something wrong or missing something??
    Is there any other way to map a new table into an existing toplink mapping? I'm using Jdev 10.1.3 Integrated workbench...
    I will really appreciate any suggestion or comment, I really have no clue why this is happening.... Thanks in advance

  • Adding objects to list

    Hi,
    I am new java. I have a probelm adding objects to list. This is the following code.
    class Test{
    List <>dataList = new ArrayList<>();
    public List<A> getAList(){
    dataList.add(new A());
    return dataList ;
    public List<B> getBList(){
    dataList.add(new B());
    return dataList;
    }In the above code what I will pass<parameterized data> to the dataList decalred as member variable?

    bhanu wrote:
    nothing common for A and B. Both A and B are different pojos. but we can tell A and B extends from Object.I tried like that
    way. But it is not working. <? extends from Object>.Both two methods have to be in the same classYou do in that case have a bad design. Why is the same list used for both. It can't be type safe so you need to cast and the user of the list might get classcast exceptions during iteration.
    Kaj

  • AIP-18510:  Error adding objects to configuration ... for business process.

    Hello,
    We are encountering this error few days after applying latest MLR patch.
    None of our agreements can be deployed, even those that were not changed in any way after the patch was applied.
    This is part of our ui.log:
    2009.02.02 at 08:49:10:409: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Formatted message
    2009.02.02 at 08:49:10:409: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Formatted message
    2009.02.02 at 08:49:10:409: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Rendering Page::pages/deployment/deploy_progress
    2009.02.02 at 08:49:10:421: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) In getVersionOnly()
    2009.02.02 at 08:49:10:965: Thread-24: IP - (ERROR) Error -: AIP-18510: Error adding objects to configuration CONFIG for business process cm_all_agreements
         at oracle.tip.configuration.B2BConfigurationBuilder.run(B2BConfigurationBuilder.java:452)
         at java.lang.Thread.run(Thread.java:534)
    2009.02.02 at 08:49:20:651: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Found Non Validation Errors
    2009.02.02 at 08:49:20:651: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Formatted message
    2009.02.02 at 08:49:20:651: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Formatted message
    2009.02.02 at 08:49:20:662: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Rendering Page::pages/deployment/deploy_error
    2009.02.02 at 08:49:20:673: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) In getVersionOnly()
    2009.02.02 at 08:49:27:961: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Rendering Page::pages/deployment/config_list
    2009.02.02 at 08:49:27:971: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) Executing Query::SELECT DISTINCT C.ID, C.CLASSTYPE, C.name, C.LifeCycleState, CA.aud_modified FROM TIP_Configuration_t C, TIP_Configuration_t_AUD CA WHERE C.ID = CA.ID AND C.LifeCycleState IN ('Active','Validated','Quiescing','Quiesced') AND CA.aud_modified IN ( SELECT MAX(aud_modified) FROM TIP_Configuration_t_AUD WHERE ID = C.ID GROUP BY ID) ORDER BY CA.aud_modified DESC
    2009.02.02 at 08:49:27:978: AJPRequestHandler-ApplicationServerThread-13: UI - (ERROR) In getVersionOnly()
    Please help as this renders our server useless.
    Best regards,
    Kamil

    Hi Kamil,
    I'm guessing you are talking about encountering these issues post MLR# 7 patch.
    Here are some of the things ypu could start off with:
    1. Check your LS Inventory to see if your patch was applied successfully
    2. Ensure that all the post installation steps were performed (in the readme file)
    3. You could rollback this patch and check if you are still getting the same error.
    4. After rollback, if your config works fine, rerapply the patch again and observe the effects.
    Thanks & Regards,
    Suhas.

  • Adding Object Mannully Vs. Adding Object in SU24 for Tranaction

    All,
    What is the diff. between Adding a missing Object Mannully in PFCG  Vs. Adding Object in SU24 for Tranaction ?
    What is the diff. between chaning Vaule for a missing Object Mannully in PFCG  Vs. Changing a value in SU24 for a Auth Ojbect ?
    Please let me know.
    From
    PT.

    Hi PT,
    There is no direct link between transactions and the auth objects assigned to them via PFCG.  Things like config and the way transaction are used have an impact on how the auths are evaluated for a given transaction.
    As you know, we use SU24 to update the SAP delivered values to meet the auth checks in our particular implementations or as per our requirements.  What this enables us to do is to ensure that when we enter a transaction, all the relevant auth objects and where appropriate fixed values are pulled through (so if you know that different usages of that tx requires different values then add the object in SU24 but leave the relevant field blank).  If you remove that transaction from the role, the auths that are also required are removed from the role too, as long as the role is not in Manual or Changed status.
    If you manually add the auth object then you have no link with the transaction/s that are required to run the object.  You can remove the transaction and the auth object value will remain in the role.  If not properly managed, you can end up with excess auths still present in roles, particularly with the S_* objects and in areas like FI where it is very easy to skip between transactions through menu options where there is no S_TCODE check, with the auth object check being the only controlling one.
    Manually entered objects definitely have their uses as long as they are properly documented and managed when maintaining roles.

  • Adding objects to the stage & acceessing stage properties - I'm a bit confused..

    Hi,
    I'm a little confused on two fronts regarding display
    programming:
    A. What the best way to add objects to the stage?
    B. How to access stage properties.
    I can do both of these when the project is an 'Action Script
    Project', but I'm having trouble when it is a 'Flex Project' (e.g.
    an MXML file). See the two attached files with questions included
    in the comment to see exactly what I mean.
    A. What the best way to add objects to the stage?
    =====================================
    In an action script project that extends Sprite I can just
    call addChild()
    In an MXML project I can add objects to the stage by first
    adding them to a UIComponent, then adding that to the stage.
    1. Is that the best way to do it?
    In this doc:
    http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_02.html
    it says that
    quote:
    Each SWF file has an associated ActionScript class, known as
    the main class of the SWF file. When Flash Player opens a SWF file
    in an HTML page, Flash Player calls the constructor function for
    that class and the instance that is created (which is always a type
    of display object) is added as a child of the Stage object. The
    main class of a SWF file always extends the Sprite class
    2. why cant I just add a sprite object direct to the stage
    without the UIComponent?
    3. What is the 'main class', and how can i get access to it?
    B. How to access stage properties.
    =========================
    In an action script project that extends Sprite I can just
    call trace(stage.framerate)
    But in an MXML file I cannot figure out how to access the
    stage properties.
    See the attached code for the things that I tried, but which
    didnt work.
    In the page:
    http://www.actionscript.org/forums/showthread.php3?t=140655
    It says
    quote:
    For stage access you have a couple of rules:
    * natively, only display objects have inherent access to
    stage
    * display objects only have a valid reference to stage if
    they're within the stage's display list (on the screen, after added
    to it with addChild)
    * The only display objects which immediately have access to
    the stage before the use of addChild (in their constructor) are the
    document/application class instance (root) and any instance from
    the library placed on the timeline (not created with AS).
    * Non-display object classes have to be passed or assigned a
    reference to the stage from another object which already has access
    to it - they cannot access it otherwise.
    4. How do I access the stage properties in the MXML project?
    5. I suspect this is related to the "main class", which I
    dont yet understand - is it?
    Sorry for the long post.
    cheers
    tom

    "tom saffell" <[email protected]> wrote in
    message
    news:gd7cm9$d1v$[email protected]..
    > Thanks Luigi - that helps a lot.
    > I hadnt seen the Flex 3 Developer Guide before - it's
    very useful.
    >
    > I now see that I can access properties of the
    application object directly
    > with
    > this.<property>.
    > However, the framerate property cannot be set by
    actionscript, only in
    > MXML (I
    > can set it in the <mx:application> tag). But I
    need to be able to set it
    > programatically, dependent on user input.
    >
    > 5. Is there a way around this?
    > 6. Can I set the stage's framerate to achieve the same
    outcome?
    >
    > I still dont understand why I cannot access the stage
    object. When I call
    > either
    this.stage or
    uic.stage * then I get
    quote:
    Cannot access
    > a
    > property or method of a null object reference.
    My understanding is
    > that I
    > can access the stage object via any display object on
    the display list.
    > I'm
    > confused about this bit..
    >
    > * - uic is a UIComponent that has been added to the
    display list (i think)
    > by
    > calling addChild(uic) from the AS3 within the
    application
    >
    > 7. How do I access stage properties in AS3 in an MXML
    project?
    http://www.adobe.com/livedocs/flex/3/html/help.html?content=05_Display_Programming_10.html
    It seems like possibly your real problem is that you're
    having trouble
    searching the Help effectively:
    http://flexdiary.blogspot.com/2008/07/getting-help-in-flex-builder.html

  • I created a vector and added objects, but the vector is empty

    I created an object called a facility, it accepts 2 strings in the creator but stores the data as a string and a float. as you can see from the code below, i have tried to create a vector object to contain facilitys and named it entries. when i add objects to this vector, the vectors size does not change, and i cannot access elements of it via their index. but when i print the vector out i can see the elements? what is going on here. i am very confused. ps, if it helps i havent worked with vectors much before.
    FacilitysTest.java
    import java.util.*;
    public class FacilitysTest {
         public static void main (String [] args) {
         Facilitys entries = new Facilitys();
         entries.add("Stage","3.56");
         entries.add("kitchen","5.00");
         entries.add("heating","2");
    //     System.out.println(entries.firstElement() );
         System.out.println("printing out entries");
         System.out.println(entries);
         System.out.println();
         System.out.println("There are "+entries.size()+" entries");
         System.out.println();
         System.out.println("modifying entry 2");
         entries.setElementAt(new Facility("lighting","1.34"), 2);
         System.out.println(entries);
         System.out.println();
         System.out.println("deleting entry 1");
         entries.remove(1);
         System.out.println(entries);
    }the following is what happens when i run this code.
    the number (0,1,2) is taken from a unique number assigned to the facility and is not anything to do with the facilitys position in the vector.
    printing out entries
    Facility number: 0, Name: Stage , Cost/Hour: 3.56
    Facility number: 1, Name: kitchen , Cost/Hour: 5.0
    Facility number: 2, Name: heating , Cost/Hour: 2.0
    There are 0 entries
    modifying entry 2
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 >= 0
    at java.util.Vector.setElementAt(Vector.java:489)
    at FacilitysTest.main(FacilitysTest.java:17)
    Press any key to continue . . .
    Facilitys.java
    import java.util.*;
    public class Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
        public void add( String name, String price ) {
             entries.add((new Facility( name, price) ));
        public Facility get(int index) {
              return ((Facility)entries.get(index));
         public float total() {
              float total = 0;
              for (int i = 0; i<entries.size();i++) {
                   total = total + ( (Facility)entries.get(i) ).getPricePerHour();
              return total;
        public String toString( ) {
            StringBuffer temp = new StringBuffer();
            for (int i = 0; i < entries.size(); ++i) {
                temp.append( entries.get(i).toString() + "\n" );
            return temp.toString();
    }

    are you reffering to where i have public class
    Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
    That's correct. That's your problem.
    i added the extends Vector, because without it i got
    the following errors
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:14: cannot find symbol
    symbol : method size()
    location: class Facilitys
    System.out.println("There are "+entries.size()+"
    " entries");That's because you haven't implemented a size method in your class.
    ^
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:17: cannot find symbol
    symbol : method setElementAt(Facility,int)
    location: class Facilitys
    entries.setElementAt(new
    w Facility("lighting","1.34"), 2);That's because you haven't implemented setElementAt in your class.
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:21: cannot find symbol
    symbol : method remove(int)
    location: class Facilitys
         entries.remove(1);
    ^That's because you haven't implemented remove in your class.
    /Kaj

  • Adding objects into query Panel and no display report

    Hi Folks,
    I had an issue with WEBI .
    Iam running the report with few objects at first time , all objects are displayed in the  table format of report.
    I saved and closed the report .
    Later  i opened the report and edited the report by adding new objects into query panel and runing it.
    but this time  i did not find the new objects in display table in report as like DeskI.
    If we find the solution for this , it will be great help to me.
    Thanks
    Mahesh

    The objects will be in the data tab. Objects are not automatically added to your report in Webi, they are made available in the data panel, and you can choose which objects to add.

  • Problem with adding objects to a collection

    Hi
    Been using this forum for a couple of years now to help me with my code, but it's the first time that I've had a problem which I couldn't find the answer for!
    I'm trying to create two classes one called Reminder and one called Engagement. The Reminder class needs to hold a list of Engagement objects, but whenever I add a new Engagement object to the ArrayList I have created in Reminder and try to retreive it I get a null value.
    If anyone can give me an idea of where I have gone wrong that would be most helpful,
    Thank you in advance,
    Steve
    Code:
    package reminder;
    import java.util.*;
    public class Reminder{
        private GregorianCalendar date       = null;
        private String            reason     = null;
        private Engagement        engagement = null;
        private List<Engagement>  appointments;
        private int year = 0;
        private int month = 0;
        private int day = 0;
        public Reminder() { //the constructor
            appointments = new ArrayList<Engagement>();
        } //end constructor
        public void add(int d, int m, int y, String r){ //this method takes an engagement object and adds it to the list
        //public void add(Engagement engagement){
            day   = d;
            month = m;
            year  = y;
            reason = r;
            appointments.add(new Engagement (new GregorianCalendar(y,m,d), reason));
            System.out.println(day + "-" + month + "-" + year);//(new Engagement (date, reason));
            appointments.add(new Engagement(new GregorianCalendar(2008,4,2), "My first appointment"));
            System.out.println("\nThere are this number of items in the list: " + appointments.size()); //this was to check the item was added
        public void getAppointments(){
            //private int arrayPosition = 0;
            //Iterator it = appointments.iterator();
            for (Iterator it = appointments.iterator(); it.hasNext();){
                System.out.println(it.next());//.appointments.toString());
                //it.next();
    package reminder;
    import java.util.*;
    import reminder.*;
    public class Engagement{
        private GregorianCalendar date = null;
        private String reason = null;
        /** Creates a new instance of Engagement */
        public Engagement(GregorianCalendar d, String r) {
            date   = d;
            reason = r;
        public String getReason() {
            System.out.println(reason);
            return null;
    public class Main { //main class to test the other classes
        /** Creates a new instance of Main */
         * @param args the command line arguments
        public static void main(String[] args) {
            Reminder reminderList = new Reminder(); //create an instance of Reminder
            reminderList.add(2,4,2008, "My first appointment");
            reminderList.add(6,10,2009, "My second appointment");
            reminderList.add(2,4,2007, "My third appointment");
            reminderList.getAppointments();
    }

    Hi Guys
    Just wanted to let you know that I have realised where I went wrong, if you look in the Engagement class there is a method called toString(); which just has a return value of null, that is why I was getting the null values!
    Sorry for wasting your time, it took me three hours to realise why it wasn't working before I contacted you and about an hour after I posted I realised what the problem was.
    One other thing... why is reminderList bad naming? I was going to call the instance reminder but because the class holds a list of objects I thought I'd call it reminderList..
    Thanks
    Steve

  • Please help how to set/get a class object in hashtable or hashmap?

    Hi, everybody.
    I'd like to generate a class-object list in hashtable.
    However, compilation is error. Here is my code:
    Hashtable ht = new Hashtable();
    Class tmp_obj;
    tmp_obj = Class.forName("my_class_name_1");
    ht.put("my_class_name_1", tmp_obj);
    tmp_obj = Class.forName("my_class_name_2");
    ht.put("my_class_name_2", tmp_obj);
    Class selected_object = ht.get("my_class_name");
    ^here compilation error: incompitable types
    Could anybody tell me where is wrong in my code and how to
    correct it?
    Thank you in advance.
    Jeff

    Look at the javadoc for Hashtable. The get method returns an Object. You will need to cast it to a Class object.
    Class selected_object = (Class)ht.get( "my_class_name" );If you are using JDK5.0, then you should look up generics.

  • Adding Objects to ArraysLists (BlueJ)

    Hi,
    Below, I have created a Book class that allows books to be created, loaned out returned and displayed.
    The next phase in this assignment is to create an ArrayList in a seperate abstract class called Library. To store the objects created in Book class. i.e. book1, book2 etc. These objects are to be added to this ArrayList.
    After that, the abstract Library class should hold a method that displays all books in the ArrayList followed by No of Books as integer value.
    Could anyone help?
    Thanks in advance.
    * Write a description of class Book here.
    * @author (Shah)
    * @version (28/01/2008)
    public class Book extends Library
        public String Author;
        public String Title;
        public String Media;
        public double Price;
        public boolean OnLoan;
        public String ShelfMark;
        public String Classification;
        public int BorrowerID;
        public String Library;
        /** Constructor for creating new object.instances (Books) */
        public Book(String author, String library, String title, String media, double price, String classification)
            /** Data input stored indirectly into instance variable*/
            Author=author;
            Title=title;
            setMedia(media);
            Price=price;
            setClassification(classification);
            Library=library;
        public void setClassification(String classification)
            Classification = classification; /** indirect access to instance variable */
            if(classification=="Fiction" || classification=="Non-fiction" || classification=="Factual" || classification=="Children" || classification=="Educational")
            { /** sets classification if one of the above are entered. */ }
            else
            {   /** Print error if one of the above is not entered. */
                System.out.println("Invalid Entry! Please Enter from the following:"); // Print Error Message
                System.out.println("Fiction, Non-Fiction, Factual, Children, Educational");
        public void setMedia(String media)
            Media = media;
            if(media=="Book" || media=="Tape" || media=="CD" )
                /** Sets Media, only from the above choices (Book, Tape, CD) */
            else
                System.out.println("You Entered Wrong Media Type! Please Enter from the following:");
                System.out.println("Book, Tape or CD.");
        public void setShelfMark()
            /** Sets the ShelfMark as "value of Classification + value of Author" */
            ShelfMark = this.Library + " " + this.Author;
        public void displayBook()
          /** call method - ShelfMark */
          setShelfMark();
          System.out.println(" ");
          /** Retrieve and Print details onto screen/canvas */
          System.out.println("Title: " + this.Title);
          System.out.println("Author: " + this.Author);
          System.out.println("Media: " + this.Media);
          System.out.println("Genre: " + this.Classification);
          System.out.println("ShelfMark: " + this.ShelfMark);
          System.out.println("On Loan?: " + this.OnLoan);
          System.out.println("Borrower ID: " + this.BorrowerID);
          System.out.println("Loan Price: " + this.Price);
        /** Require BorrowerID and Date for Loan */
        public void LoanOut(int borrowerID)
            /** If not already loaned, Loan book to requestee */
            if(OnLoan==false)
                BorrowerID=borrowerID;
                /** BorrowerID Range is set between 1-1000, value outside this range is not allowed */
                if (borrowerID<1 || borrowerID>1000)
                    System.out.println("Out of Range. BorrowerID must be between 1-1000");
                else
                    /**Book is now on Loan */
                    OnLoan = true;
                    /** Prints/Shows details of Book Loaned */
                    displayBook();
                    System.out.println("This book is now loaned out to you!");         
                else
                /**Ensures you cannot loan a book that is already loaned to you */
                System.out.println("This book is already Out On Loan!");
        public void ReturnBook()
                if(OnLoan==true)
                BorrowerID=0;
                OnLoan=false;
                displayBook();
                    System.out.println("This book has now been returned");
                else
                    System.out.println("This Book Has not been loaned out");  
    }

    TopDollar wrote:
    I checked, your code which is right, however, i still cant get it to work. i tried this:
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.*;
    public abstract class Library
    public static ArrayList BooksDB = new ArrayList();
    public Book search;
    public void Display()
         int index = 0;
    while(index < BooksDB.size()) {
    System.out.println(BooksDB.get(index));
    index++;
    public void displayInfotwo()
    Iterator it = BooksDB.iterator();
    while(it.hasNext())
    ((Book)(it.next())).displayBooks();
    Upgrage to atleast Java 5 and you're laughing: combine generic collections with the enhanced for loop and that mess of a
    displayInfotwo becomes:
    public void displayInfotwo() {
        for (Book book : BooksDB) {
            book.display();
        }

  • Adding Objects to Vector

    Hi,
    I have a class that has two private variables:
    private String tableName;
    private Vector iffields;
    The vector is supposed to be filled with objects of
    another class called DIFField.
    How can I write a method that adds DIFFields to this
    iffields Vector in a way that they all don't refer to
    the same Object??
    e.g.
    in my main code I do: DIFField afield = new afield("blabla","blabla");
    afield.setCode("111");
    afield.setSign("+");
    I want to keep using that same afield (in a loop) for adding new
    fields to the iffields vector. I could do this if I could set everything
    in the constructor, I know that, but that's something that's not possible. (otherwise: iffields.addElement(new DIFField("blabla","blabla");)
    Can anybody help me??
    Regards,
    Sven

    How can I write a method that adds DIFFields to this
    iffields Vector in a way that they all don't refer to
    the same Object??The only way to do that, ie, the normal way, would be to use the new operator and contruct each object within your loop. You can still use the same variable name, no problem there.
    I could do this if I
    could set everything
    in the constructor, I know that, but that's something
    that's not possible. (otherwise:
    iffields.addElement(new DIFField("blabla","blabla");)What do you mean that is impossible? Have you tried instantiating your DIFField, calling the methods, then adding it to the vector?
    for( int i = 0 ; i < 5 ; i++ )
       DIFField df = DIFField( "foo", "bar" ) ;
       df.setCode( "111" ) ;
       df.setSign( "+" ) ;
       iffields.addElement( df ) ;
    }

  • Adding objects to a Map

    Hi all
    I have created a program that add objects to a Map
    Code below shows the method used when added
    public String add(int bookNumber, String title, String releaseYear, String author)
    Book book = new Book(bookNumber, title, releaseYear, author);
    if (library.containsKey(new Integer(book.getBookNumber())))
    return "Failure - Book is already in the Library";
    library.put(new Integer(book.getBookNumber()), book);
    return "Success Book Added";
    Trouble is when it adds the book(object) to the collection(map) it adds it anywhere in the map, eg I could have a book in place 1001 then the next book in place 1056, is there anyway I can get the method to add the object in order EG. There is a book in 1001 and when I add another object it goes to place 1002
    Any help would be great
    Thank all for your time
    James

    I don't know why you'd care about where in the Map a paticular object is but if you want it sorted you could try a TreeMap. And if you want unique keys then use a HashMap.

  • Adding Objects To a HashSet, overriding equals and hashCode

    Hi everyone,
    I'm trying to add objects to a HashSet, using a string identifier (an attribute of these objects) to determine if two objects are equal.
    I have a class 'IntExpEvent' class that overrides the equals and hashCode methods.
    public class IntExpEvent implements ExperimentalEvent{
    public int correctAnswer;
    public String identifier;
    public IntExpEvent(String id, int correctAnswer){
         this.identifier = id;
         this.correctAnswer=correctAnswer;
    public String getID(){
         return(this.identifier);
    public boolean equals(ExperimentalEvent e){
         return (this.identifier.equals(e.getID()));
    public int hashCode(){
         System.out.println((this.getID()).hashCode());
         return (this.getID()).hashCode();
    private int hashCode=-1;
    public int hashCode() {
         if(hashCode==-1) {
         char[] ca=getID().toCharArray();
         for(int x=0;x<ca.length;x++) {
              hashCode+=ca[x];
         return(hashCode);
         IntExpEvent e1 = new IntExpEvent("test_IntExpEvent",4);
         IntExpEvent e2 = new IntExpEvent("test_IntExpEvent",6);
         HashSet hs = new HashSet();
         System.out.println(hs.add(e1));
         System.out.println(hs.add(e2));
    I can still add both e1 and e2 to the HashSet, which is what I'm trying to stop from happening. i.e. objects with the same identifier should be treated as the same object, allowing only one to be added to the HashSet. Does anyone know how I can do this? Help would be greatly appreciated

    In fact you don't override the equals method. The signature defined in the Object class is
      boolean equals(Object o)In your case it is
      boolean equals(ExperimentalEvent e)So instead of overriding the method you're overloading it.
    Regards

  • Problem with Serializable JDO objects containing Hashtables

    Hi,
    I have a simple JDO object which contains a Hashtable and I would like to
    declare as Serializable. It seems though, that whenever I serialize this
    object, I get a NullPointerException. I've written a bare-bones test case
    and reproduced the exception, so I suspect this may be an enhancement issue.
    Thanks,
    Eric
    Exception in thread "main" javax.jdo.JDOException
    NestedThrowables:
    java.lang.NullPointerException
    at
    sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteC
    all.java:245)
    at
    sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
    at
    org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invoke(Unknown
    Source)
    at
    org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericPr
    oxy.java:357)
    at
    org.jboss.ejb.plugins.jrmp.interfaces.StatefulSessionProxy.invoke(StatefulSe
    ssionProxy.java:136)
    at $Proxy1.getHash(Unknown Source)
    at test.HashEjb.getHash(Unknown Source)
    at test.Test.doIt(Test.java:13)
    at test.Test.main(Test.java:7)

    Thanks for the prompt reply Patrick. I can hold off on this until early
    next week...
    "Patrick Linskey" <[email protected]> wrote:
    This is a confirmed bug. We do not correctly deserialize any proxy map
    classes.
    How soon is ASAP? None of us can work on it until later this evening at
    the earliest.
    -Patrick
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

Maybe you are looking for

  • RTSP Embedded for Internet Explorer

    Can anyone explain how to embed a RTSP file into a web page for INternet Explorer? Or even point me to an example of someone else doing this on the web? I cannot seem to find any examples of true RTSP files working inside IE. I am using QTSS for both

  • Typeahead function in search field inside Facebook does not work in Firefox 13.0

    Until 3 or 4 days ago, cool typeahead function inside search field inside Facebook always worked in Firefox. Now since 4 days ago, it does not work. But the typeahead function works inside search field inside Facebook on Internet Explorer BUT I prefe

  • How can I uncheck "Binary Index" if I have already disabled all keywords?

    A week or so ago, I asked a question about the binary index and how to delete topic keywords so I could uncheck the box on the "Project Settings" page.  I received a great, helpful response: " First, click View > Pods > Project Manager. Locate the In

  • List Output Default for F.01

    Before the ECC upgrade the default selection for List Output was ALV grid control. After the ECC upgrade the default selection for List Output is Classical list. We would like to change the default back to ALV grid control and would greatly appreciat

  • How to make sense of the multiple photo subfolders in my iphone?

    I used to manually copy and paste newly taken photos from my iphone into my computer. Ever since I bought iphone 6, there is suddenly an onslaught of subfolders created, with seemingly no patterns how the photos and videos are sorted. I am now unable