2 bucks for !! java basic question

Posted by Max on Stack Overflow See other posts from Stack Overflow or by Max
Published on 2010-06-06T13:33:29Z Indexed on 2010/06/06 14:02 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

How can I get a specific value from an object? I'm trying to get a value of an instance for eg.

ListOfPpl newListOfPpl = new ListOfPpl(id, name, age);
Object item = newListOfPpl;

How can I get a value of name from an Object item?? Even if it is easy or does not interest you can anyone help me??

Edited: I was trying to build a binary tree contains the node of ListOfPpl, and need to sort it in the lexicographic. Here's my code for insertion on the node. Any clue??

    public void insert(Object item){
    Node current = root;
    Node follow = null;
    if(!isEmpty()){
        root = new Node(item, null, null);
        return;
    }boolean left = false, right = false;
    while(current != null){
    follow = current;
        left = false;
        right = false;
                      //I need to compare and sort it
             if(item.compareTo(current.getFighter()) < 0){
                                 current = current.getLeft();
            left = true;
        }else {
        current = current.getRight();
            right = true;
        }
        }if(left)
            follow.setLeft(new Node(item, null, null));
        else
            follow.setRight(new Node(item, null, null));
    }

© Stack Overflow or respective owner

Related posts about java

Related posts about homework