Question:
Java array - [] need help !?
anonymous
2009-11-28 06:47:34 UTC
Im trying to create a program where you can create new 'records' of people (name,age etc). How is this possible? i know about arrays, but in my case im not sure how many records there will be, is there a ++ increment method of increasing the array if needed, and storying the details inside it? thanks..
Four answers:
modulo_function
2009-11-28 08:08:17 UTC
Java has many classes for collections. ArrayLIst is one, Vector is another. Some of these work like arrays except the 'grow' as elements are added. Take a look at the collections tutorial:



http://java.sun.com/docs/books/tutorial/collections/TOC.html



For you I think that an ArrayList is probably best:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html
anonymous
2016-12-10 10:53:10 UTC
Re:... the minimum and optimal numbers. you decide on 2 protecting (storage) aspects. (Variables.) One to hold the min value and one to hold the max value. while your application starts, initialize the min value with some thing like 9999999. Then, via fact this methodology reads each and all the ten numbers, take a 2d and evaluate that quantity to the cutting-edge quantity interior the min variable and that quantity to the cutting-edge quantity interior the max variable. If this cutting-edge quantity examine is decrease than the present min value, then THAT quantity will become the recent min variable. flow it in there. that's going to the 1st time via. keep in mind we began it out with 9999999, so of direction it's going to be decrease. If this cutting-edge quantity examine is super than the present max value, then THAT quantity will become the recent min variable. flow it in there. that's going to the 1st time via. that's going to start up as 0. that's it. while all ten numbers are appeared at and in comparison in this way, your min variable will incorporate the backside quantity entered, and your max variable will incorporate the biggest value entered.
Steven V
2009-11-28 07:06:28 UTC
public class Record() {

private String name;

private int age;

//etc.



//setters and getters

}



List records = new ArrayList(); // This will allow you to put in as many records as you'd like.

Record record = getNextRecord(); // This is a method you'd implement to read in the record.

records.add(record);

for(Record record2: records) {

System.out.println(record2);

}
Lie Ryan
2009-11-28 07:00:04 UTC
Use ArrayList http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html or LinkedList http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html or Vectors http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...