Results 1 to 6 of 6

Thread: Using an ArrayList

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

  5. #5
    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)

  6. #6
    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);
    }
    }

Similar Threads

  1. Finding items with ArrayList
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 02:03 AM
  2. Multithreading and ArrayList
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 05:16 AM
  3. Initialize an ArrayList
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 04:13 AM
  4. ArrayList not working
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 07-02-2010, 04:18 AM
  5. ArrayList and type the return
    By manjava in forum Software Development
    Replies: 2
    Last Post: 09-05-2009, 11:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,821,049.84946 seconds with 16 queries