-
Using an ArrayList
Hello,
I created a class of variables that I use is from another program (based on LTE, which recuperates the variables to be stored in a database). I've defined variables of any type (string, int, date ...). I define or recovered from the set and get methods. So far, no problem. I would now like to know if it is possible to create in such a class "array" and how to define the get and set methods for this type of variable. Thank you in advance for your advice.
-
Re: Using an ArrayList
Hello,
You could make it inherit from ArrayList and define Get and Set with Iterator, but I do not see how you will do. For you must provide and retrieve multiple items and call the method several times to scroll through the list. So I remain skeptical about the usefulness of such methods. But why not use existing types? This is would be much more easier for you to handle in your program.
-
Re: Using an ArrayList
Hello,
Even I am interested in this topic , because a few days before even I was thinking of the same. In the above post what you have explained or tried to say, I have not understood much about it. What I understood in any case is that you advise me to create a new class that contains only what I want to address in my array, right? If I am wrong then please guide me with the correct. Thanks in advance.
-
Re: Using an ArrayList
Hello,
I think with Java 5 you can create a class of type ArrayList, which therefore contains an ArrayList, but you can specify types of elements in your ArrayList by
Here is the syntax what I am trying to explain
Code:
public class ArrayList MyList Extends <the element>
If you need any more information on arraylist then you can visit the sun's official site and there you can find more detailed information on the same.
-
Re: Using an ArrayList
Hello,
There is no problem because your list contains objects Integer, that is what I said. Now, if you put in your list a "int" and that it works is that the problem is masked by the "autoboxing" java, but in reality is an Integer which is placed in the list. However, before using the function autoboxing, you ought to learn to understand how it works. It may be useful to you to understand what you actually do (and if one day you have to program in java 1.4, where this functionality does not exist)
-
Re: Using an ArrayList
Hello,
See, if the following example helps you
Code:
class Ademo {
public static void main(String args[]) {
// create an array list
ArrayList arr = new ArrayList();
System.out.println(" size of arr: " +
arr.size());
// add elements to the array list
arr.add("C");
arr.add("A");
arr.add("E");
arr.add("B");
arr.add("D");
arr.add("F");
arr.add(1, "A2");
System.out.println("Size of arr after additions: " +
arr.size());
// display the array list
System.out.println("Contents of arr: " + arr);
// Remove elements from the array list
arr.remove("F");
arr.remove(2);
System.out.println("Size of arr after deletions: " +
arr.size());
System.out.println("Contents of arr: " + arr);
}
}
Page generated in 1,710,813,549.35294 seconds with 10 queries