Results 1 to 2 of 2
- 03-17-2008, 06:13 PM #1Member
- Join Date
- Jan 2008
- Rep Power
grabbing an item from an arraylist.
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.
- 03-17-2008, 09:25 PM #2Java 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);
- By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM
- By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 09:48 PM
- By yllawwally in forum New To JavaReplies: 0Last Post: 12-18-2007, 09:45 PM
- By kizilbas1 in forum New To JavaReplies: 11Last Post: 12-05-2007, 08:30 PM
- By kleave in forum New To JavaReplies: 2Last Post: 11-19-2007, 07:45 PM