Results 1 to 2 of 2
  1. #1
    newtojava7 is offline Member
    Join Date
    Jan 2008
    Posts
    16
    Rep Power
    0

    Default grabbing an item from an arraylist.

    hello,

    i have many strings in an arraylist. im allowing the user to type in a string into the JTextField, and if the string matches a string in the arraylist, that string will be displayed into a JList.

    my question is after the program finds the string, how can I grab that string out of the arraylist to display in the JList? I know I could just set the JList to show whatever string was typed into the textfield, however I want it to display the string in the arraylist instead.

    thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    List<String> list = new ArrayList<String>();
    // Get String at index 2 in list.
    int index = 2;
    String s = list.get(index);
    // [i]get[/i] returns an Object  see api.
    // So if not using generics you will need to cast the
    // value returned by/from the [i]get[/i] method to the
    // type you put into the list.
    List list = new ArrayList();
    int index = 2;
    String s = (String)list.get(index);

Similar Threads

  1. Replies: 2
    Last Post: 04-21-2008, 11:43 AM
  2. ArrayList
    By kizilbas1 in forum New To Java
    Replies: 1
    Last Post: 01-12-2008, 08:48 PM
  3. linked list nodes all refernce same item.
    By yllawwally in forum New To Java
    Replies: 0
    Last Post: 12-18-2007, 08:45 PM
  4. ArrayList
    By kizilbas1 in forum New To Java
    Replies: 11
    Last Post: 12-05-2007, 07:30 PM
  5. New to arraylist
    By kleave in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 06:45 PM

Posting Permissions

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