Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Using an ArrayList

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
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.

Reply With Quote
  #2  
Old 04-03-2010
Member
 
Join Date: Nov 2009
Posts: 333
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.
Reply With Quote
  #3  
Old 04-03-2010
Member
 
Join Date: Dec 2009
Posts: 204
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.
Reply With Quote
  #4  
Old 04-03-2010
Member
 
Join Date: Nov 2009
Posts: 518
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>
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.
Reply With Quote
  #5  
Old 04-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
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)
Reply With Quote
  #6  
Old 04-03-2010
Member
 
Join Date: Dec 2009
Posts: 296
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);
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:42 AM.