Results 1 to 2 of 2
- 03-17-2008, 05:13 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 16
- Rep Power
- 0
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
- 03-17-2008, 08:25 PM #2
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
-
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 08:48 PM -
linked list nodes all refernce same item.
By yllawwally in forum New To JavaReplies: 0Last Post: 12-18-2007, 08:45 PM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 11Last Post: 12-05-2007, 07:30 PM -
New to arraylist
By kleave in forum New To JavaReplies: 2Last Post: 11-19-2007, 06:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks