Indeed, learning Lists and vectors are not 100% needed or useful !
When dealing with larger data and larger scale of applications with more information to store, sort, delete and etc. Lists and vectors will reduce the speed response !
Arrays always faster than Lists/vectors in Java :>
Sure, but they are still much more comfortable to use and should be learned anyway. And i don't see big problem using them during "learning period" while systems aren't huge and companies don't depend on them...
Storing large amounts of data in these structures is nothing, the problem with them is frequent insertion and deletion. Arrays are not always faster, because when you insert a new item into the array you do not have to resize the array, where as with the vector you do. However, if you need the size of the array to grow, you would have to manually resize it, and copy the old content. This is slow, and essentially is what the vector does. Thus if you are inserting and deleting often, you are resizing and moving items to fill gaps often, which is very inefficient.
I agree you should learn to use them, but you should learn when to use them as well.
Last edited by chili5; 07-05-2009 at 04:28 AM.
Thanks for the replies.
I have encounter a problem now hope that you guys can help me.
I cant figure out what is the problem again. >< Here is my code.
Code:public class Game{ private Person players[]; //--------------------------------- public Game(){ players=new Person[3]; players[0]=new Person(); players[1]=new Person(); players[2]=new Person(); } public void setPlayers(Person p, int a){ players[a]=p; } public Person getPlayers(int a){ return players[a]; } public static void main(String args[]){ Game g = new Game(); Person p = g.setPlayers(p, 0); p.setName("kl"); p.setHp(9); p.setSp(8); p.setExp(0.5); } }Thanks very much.Code:public class Person{ private String name; private int hp; private int sp; private double exp; private Jobskill skills[]; private Equipment defense[]; private Equipment attack[]; //--------------------------------------------- public Person(){ name=""; hp=10; sp=10; exp=0.0; skills=new Jobskill[5]; skills[0]=new Jobskill(); skills[1]=new Jobskill(); skills[2]=new Jobskill(); skills[3]=new Jobskill(); skills[4]=new Jobskill(); defense=new Equipment[5]; defense[0]=new Equipment(); defense[1]=new Equipment(); defense[2]=new Equipment(); defense[3]=new Equipment(); defense[4]=new Equipment(); attack=new Equipment[5]; attack[0]=new Equipment(); attack[1]=new Equipment(); attack[2]=new Equipment(); attack[3]=new Equipment(); attack[4]=new Equipment(); } public void setName(String a){ name=a; } public String getName(){ return name; } public void setHp(int b){ hp=b; } public int getHp(){ return hp; } public void setSp(int c){ sp=c; } public int getSp(){ return sp; } public void setExp(double e){ exp=e; } public double getExp(){ return exp; } public void setSkills(Jobskill j, int x){ skills[x]=j; } public Jobskill getSkills(int x){ return skills[x]; } public void setDefense(Equipment e, int y){ defense[y]=e; } public Equipment getDefense(int y){ return defense[y]; } public void setAttack(Equipment e, int z){ attack[z]=e; } public Equipment getAttack(int z){ return attack[z]; } }
Thanks for the replies.
I have encounter a problem now and hope you guys can help me out. I keep getting an error saying "incompatible types. Found: void. Required: Person.". Here is my code...
Code:public class Person{ private String name; private int hp; private int sp; private double exp; private Jobskill skills[]; private Equipment defense[]; private Equipment attack[]; //--------------------------------------------- public Person(){ name=""; hp=10; sp=10; exp=0.0; skills=new Jobskill[5]; skills[0]=new Jobskill(); skills[1]=new Jobskill(); skills[2]=new Jobskill(); skills[3]=new Jobskill(); skills[4]=new Jobskill(); defense=new Equipment[5]; defense[0]=new Equipment(); defense[1]=new Equipment(); defense[2]=new Equipment(); defense[3]=new Equipment(); defense[4]=new Equipment(); attack=new Equipment[5]; attack[0]=new Equipment(); attack[1]=new Equipment(); attack[2]=new Equipment(); attack[3]=new Equipment(); attack[4]=new Equipment(); } public void setName(String a){ name=a; } public String getName(){ return name; } public void setHp(int b){ hp=b; } public int getHp(){ return hp; } public void setSp(int c){ sp=c; } public int getSp(){ return sp; } public void setExp(double e){ exp=e; } public double getExp(){ return exp; } public void setSkills(Jobskill j, int x){ skills[x]=j; } public Jobskill getSkills(int x){ return skills[x]; } public void setDefense(Equipment e, int y){ defense[y]=e; } public Equipment getDefense(int y){ return defense[y]; } public void setAttack(Equipment e, int z){ attack[z]=e; } public Equipment getAttack(int z){ return attack[z]; } }Thanks very much.Code:public class Game{ private Person players[]; //--------------------------------- public Game(){ players=new Person[3]; players[0]=new Person(); players[1]=new Person(); players[2]=new Person(); } public void setPlayers(Person p, int a){ players[a]=p; } public Person getPlayers(int a){ return players[a]; } public static void main(String args[]){ Game g = new Game(); Person p = g.setPlayers(p, 0); p.setName("kl"); p.setHp(9); p.setSp(8); p.setExp(0.5); } }
Sorry for my clumsy mistake of posting two similar posts... This is due to my Internet connection.
I apologize for that. Sorry.
Well, setPlayers returns void, so why would you want to assign it to Person p?Code:Person p = g.setPlayers(p, 0);
try this.
i'm just guessing now.Code:g.setPlayers(p, 0);
next time, please describe the problem too.. .
Sorry for my unclear description.
Player is an array of Person. I want to set new values to the properties of the person p. I know maybe my method of doing it is wrong but i just cant figure out how to do that.
How to set new value of an object's properties where the object is stored inside an array?
Facing headache now. ><
Please correct me if i use the wrong term. Thanks.
players[0].yourMethod();How to set new value of an object's properties where the object is stored inside an array?
it's simple as that..
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks