برامج

سؤال إلى من يتقن الـ Java [الأرشيف] - برامج نت

المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : سؤال إلى من يتقن الـ Java


smsm_n
04-27-2007, 01:42 PM
بسم الله الرحمن الرحيم

سؤالي بسيط جدا ولكنيي حاولت في أن أجد حلا له دون جدوى.

سؤالي هو كيف أستطيع أن أعمل ArrayList من Object أنا أنشأته سابقا وكيف أستطيع التعامل مع المتغيرات الموجود لكل Object من خلال الـ ArrayList يعني مثلا لو كل Object ليه عمر (سن) وعايز أرتب الـ Object على حسب هذا العمر أنا عارف إن فيه دالة جاهزة بترتب بس إزاي استعملها.

معلش على الإطالة وشكرا جزيلا

zakimoulayabdellah
04-27-2007, 07:14 PM
ok friend
soory but i write in french

bon pour le but de ton class j ai decrit toute les choses concernant java avec le field Array
j ai crée pour toi une classe Array qui contient un object
et qui dispose des méthodes add
remove
maint cette classe sera util pour toi
j espere que tu vas l etendre pour que tu fasse ce que tu veux


public class Array{
private Object t[];
public Array(){
}


c est le debut du class

la methode add

public int add(Object obj){
if (t==null) {
t=new Object[1];
t[0]=obj;
return 1;
}
Object temp[]=new Object[t.length+1];
for(int i=0;i<t.length;i++) temp[i]=t[i];
temp[temp.length-1]=obj;
t=temp;
return 1;
}

la methode add avec un idice

public int add(Object obj,int ind){
if (ind<t.length && ind>=0){
Object temp[]=new Object[t.length+1];
int i=0;
for(i=0;i<ind;i++) temp[i]=t[i];
temp[ind]=obj;
for(int j=i+1;j<=t.length;j++ ) temp[j]=t[j-1];
t=temp;
return 1;
}
return 0;
}

la methode remove avec un indice

public int remove(int ind){
if (ind<t.length && ind>=0){
Object temp[]=new Object[t.length-1];
int i=0;
for(i=0;i<ind;i++) temp[i]=t[i];
for(int j=i+1;j<t.length;j++ ) temp[j-1]=t[j];
t=temp;
return 1;
}
return 0;
}

la methode remove

public int remove(Object obj){
for(int i=0;i<t.length;i++)
if (t[i]==obj){
remove(i);
return 1;
}
return 0;
}

la methode length

public int length(){
return t.length;
}

la methode get pour recupere l element

public Object get(int ind){
return t[ind];
}

la methode set pour affecte

public void set(Object obj,int ind){
t[ind]=obj;
}

la methode is null

public boolean isNull(){
if (t==null)
return true;
return false;
}