Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    Hi
    May I recommend something not so OO reliant where extra classes are required?

    'Samsgetmoney' original request for a key/string value pair system.
    Wouldn't a HashMap be much more simple ?

    Refer to: http ://java.sun.com/j2se/1.5.0/docs/api/java/util/HashMap.html - for more details.
    ..................^ remove this space
    Note that you can't have multiple Keys, they are unique.

    Example code:
    import java.util.HashMap;

    public class HashMapper {

    public static void main(String[] args) {
    HashMap<Integer , String> myMap = new HashMap<Integer, String>();
    myMap.put(1,"String1");
    myMap.put(2,"String2");
    myMap.put(3,"String3");
    myMap.put(4,"String4");
    System.out.println(myMap.get(1));
    System.out.println(myMap.get(2));
    System.out.println(myMap.get(3));
    System.out.println(myMap.get(4));
    }
    }

  2. #22
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    Ahhhk, Nevermind! realised he wants the associated 'key' or int value be able to change, HashMap doesn't cater for that it's more of a dictionary type :-)

    But yes, I agree that for that your best off having a person class with getters/setters for 'getCoolness' 'getName' and obviously setters and return them as an object in the ArrayList. :)

  3. #23
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    dam i didnt think it would have to be that complicated..i thought java had certain things for this dam.

  4. #24
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Here I publish some vector methods for more information
    Vector vector=new Vector();
    int n=1;//any num or iterator
    vector.elementAt(n);
    vector.addElement("200");
    vector.setElementAt("200",n);
    vector.removeElementAt(n);
    vector.removeAllElements();
    vector.indexOf("200");
    vector.size(); //equals like array.length
    vector.isEmpty();//means the same )
    //and so on
    don't write
    people.element(sam, ++100);
    but put it to loop
    String text;
    for(int i=0; i<vector.size(); i++){
    text=vector.elementAt(i).toString();
    }
    got it? report
    Last edited by Webuser; 02-18-2009 at 05:55 AM.

  5. #25
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    When i say:
    people.element(sam, ++100);

    i want to add 100 more to "sam"

  6. #26
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by Samgetsmoney View Post
    When i say:
    people.element(sam, ++100);

    i want to add 100 more to "sam"
    100 more what? elements or what? 100 more "sam" elements to vector?

  7. #27
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    no an int
    like lets say int coolness
    "sam" gets 100 added to his coolness

  8. #28
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    what is "element", what is "sam" and why is it so difficult for you to add 100 to it? have you even tried running the code you give us? is there an output you get that you expected to be something else? your details are really sparse.

  9. #29
    Samgetsmoney is offline Member
    Join Date
    Feb 2009
    Posts
    32
    Rep Power
    0

    Default

    no sorry guys im thinking to use a hashmap i read about it and it sounds right for what i need..

  10. #30
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    Can you post the code when your done? so we can all get more of an understanding of what you were trying to achieve and how you solved it!

    Cheers
    John

  11. #31
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    i'd actually prefer to see pseudocode or heavily commented code since he isn't too sure how to go about accomplishing whatever it is that he's trying to do.

  12. #32
    JohnnyR is offline Member
    Join Date
    Feb 2009
    Posts
    46
    Rep Power
    0

    Default

    I would to, but it's obvious that no pseudo code was ever constructed and it was dive strait in :) I mostly just want to know what he was trying to do as it's confusing the hell out of me, so was his other post about 3 int values and changing there values!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Arraylist
    By gnarly hogie in forum New To Java
    Replies: 2
    Last Post: 12-11-2008, 01:59 AM
  2. Replies: 2
    Last Post: 04-21-2008, 11:43 AM
  3. ArrayList problem with images
    By Cymro in forum New To Java
    Replies: 2
    Last Post: 02-05-2008, 06:22 PM
  4. ArrayList problem
    By khamuruddeen in forum New To Java
    Replies: 7
    Last Post: 12-22-2007, 05:46 AM
  5. ArrayList problem (finding largest no)
    By bugger in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •