الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال في المصفوفات

مغلق
بدأه عمر أبو قعدان في 11 نوفمبر 2002 · 4 رد · 669 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

كيف أستطيع تعريف مصفوفة من الكائنات و للتوضيح

عندي Class من نوع صندوق كيف أستطيع عمل مصفوفة منها

#3

You better use Vector and not Array especially if you do not know the number of objects you are going to store.

//create the vector

Vector v = new Vector();
//your object
Box b = new Box();

//store your object

v.addElement(B);

//when you want to get your object back,just cast it to its type

Box myStoredBox = (Box) v.elementAt(index);

//index is the index of the vector,example 0

Here is the solution using Arrays:

//create the array
Box[] b = new Box[10];
this means you can store 10 objects of type Box

//store a new Box in the first position
b[0] = new Box();
//please note that array starts from 0 and NOT 1

//do the same for storing other objects by changing the index
b[1] = new Box();

Ramadan Karim inshallah

Madani

#4

عودا حميدا أخ مدنى - عمر

خالد المصرى

#5

شكرا لك أخ مدني على الخدمة أنا ممنون لك(f) (f)

هذا الموضوع مغلق.

مواضيع مشابهة