Results 1 to 6 of 6
  1. #1

    Default Array of The same Object..Need some help..


    Hi guyz...Patabang lang unta ko..

    I need an array of Object(The same object) nya karn gamit ko ug ArrayList but sa akong pag-gamit kay d nko ma display ang object..ang I display niya kay ang address sa object...

    FYI..
    array of Object(The same object)..nya in every object naa koy method na DisplayProductName(). mao na akong gusto i display pero d ko maka-access sa object..I donno y...

    patabang ko ninyo bro...

    here's the code:

    ArrayList orderlist = new ArrayList();

    orderlist.add(item1); /*Item1 is an instantiation of Class Item with a variable na product w/c is a reference to product Object */

    nya karn ang display niya kay ingani ra:
    Output

    [POS.Item@9304b1]


    patabang lang ko mga fellow istoryans...
    Salamat and more Power...! 8|

  2. #2

    Default Re: Array of The same Object..Need some help..

    i type cast pa siya nimo to the original class niya. Somewhat like this:

    Code:
    SomeClass item = new SomeClass();
    ArrayList list = new ArrayList();
    
    list.add(item);
    
    ...
    temp = (SomeClass) list.get(0);
    ...

  3. #3

    Default Re: Array of The same Object..Need some help..

    Hi. Java ni siya noh?

    Para ma display ang imong gusto idisplay na string, i-override nimo ang public String toString() method () sa object.
    Ang return value sa toString() method mao ang ma display kung imong ipasa ang object sa mga methods nga tigdisplay ug string, like System.out.println, etc.

    example if mao ni imong object:

    public class MyObject {

    private int i = 0;

    public MyObject(int i) {
    this.i = i;
    }

    public String displayProductName() {
    return "I'm a string from object no. " + this.i;
    }

    public String toString() {
    return displayProductName();
    }

    }


    ... and mao ni imong main method:

    public static void main(String[] args) {

    // btw, butangi ug type ang imong list... Mao ning sakto pag-gamit ug
    // collection.
    ArrayList<MyObject> list = new ArrayList<MyObject>();

    MyObject obj1 = new MyObject(1);
    MyObject obj2 = new MyObject(2);

    list.add(obj1);
    list.add(obj2);

    System.out.println("Output: ");
    System.out.println(list);
    }


    Mao ni iyang output:

    Output:
    [I'm a string from object no. 1, I'm a string from object no. 2]


    I hope na-gets nimo akong gipang-yawyaw. Hehehe.

  4. #4

    Default Re: Array of The same Object..Need some help..

    better if you use List instead of an Array

  5. #5

    Default Re: Array of The same Object..Need some help..

    Quote Originally Posted by idolpunk View Post
    Hi guyz...Patabang lang unta ko..

    I need an array of Object(The same object) nya karn gamit ko ug ArrayList but sa akong pag-gamit kay d nko ma display ang object..ang I display niya kay ang address sa object...

    FYI..
    array of Object(The same object)..nya in every object naa koy method na DisplayProductName(). mao na akong gusto i display pero d ko maka-access sa object..I donno y...

    patabang ko ninyo bro...

    here's the code:

    ArrayList orderlist = new ArrayList();

    orderlist.add(item1); /*Item1 is an instantiation of Class Item with a variable na product w/c is a reference to product Object */

    nya karn ang display niya kay ingani ra:
    Output

    [POS.Item@9304b1]


    patabang lang ko mga fellow istoryans...
    Salamat and more Power...! 8|
    ask lang ko unsa manang 9304b1 nimo? Item name na? dali ra mana bay...

  6. #6

    Default Re: Array of The same Object..Need some help..

    pero much better list imo gamiton kaysa Array kay List is dali ra man gud siya gamiton kay sa mag array paka.

  7.    Advertisement

Similar Threads

 
  1. Birds of the same feather flock together...tinoud ni?
    By neishan731 in forum General Discussions
    Replies: 154
    Last Post: 09-12-2017, 02:26 PM
  2. i hope im on the right thread,i need some help on this...
    By jemar in forum Software & Games (Old)
    Replies: 2
    Last Post: 05-05-2010, 03:40 PM
  3. Franciscans of the Immaculate Cebu Needs Help
    By teeedert in forum General Discussions
    Replies: 6
    Last Post: 07-24-2008, 09:41 PM
  4. Hi Guys! Need some help and advice about an MLM Company
    By joan_v in forum Business, Finance & Economics Discussions
    Replies: 14
    Last Post: 06-21-2006, 06:36 PM
  5. Replies: 2
    Last Post: 06-16-2005, 03:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top