|
| ||||||||||
| Tags: arraylist, components, hashmap, hashtable, map, memory heap, tools |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Using an ArrayList
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. |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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 Code: <elements> Code: public class ArrayList MyList Extends <the element> |
|
#5
| |||
| |||
| 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) |
|
#6
| |||
| |||
| 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);
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Using an ArrayList" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding items with ArrayList | ISAIAH | Software Development | 5 | 18-02-2010 01:03 AM |
| Multithreading and ArrayList | Logan 2 | Software Development | 5 | 09-02-2010 04:16 AM |
| Initialize an ArrayList | TechGate | Software Development | 5 | 09-02-2010 03:13 AM |
| ArrayList not working | Remedy | Software Development | 5 | 07-02-2010 03:18 AM |
| ArrayList and type the return | manjava | Software Development | 2 | 09-05-2009 11:15 PM |