Results 1 to 3 of 3
  1. #1
    right2001 is offline Member
    Join Date
    Feb 2009
    Posts
    25
    Rep Power
    0

    Default A simple List question

    List<PrintWriter> writers = new ArrayList<PrintWriter>();

    Can anybody tell me what that means? Does it construct a new List or ArrayList?

    :rolleyes:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Yes. It constructs a new ArrayList which is also a List.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    List is an interface and can't be constructed directly. ArrayList is a class that implements the List interface. By coding this way, if you later decide that you would prefer to use a LinkedList instead of an ArrayList, you only have to change minimal code. The variable still remains a List and none of the uses of the variable change.

Similar Threads

  1. Super simple question
    By jigglywiggly in forum New To Java
    Replies: 3
    Last Post: 01-26-2009, 01:17 AM
  2. Linked List Question
    By CirKuT in forum New To Java
    Replies: 4
    Last Post: 12-10-2008, 06:56 PM
  3. Simple append question
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-20-2007, 11:40 PM
  4. Probably a really simple question...
    By ibanez270dx in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 01:27 AM
  5. Simple question of JTable
    By carl in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •