Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Using getSelectedValuesList() instead of the deprecated getSelectedValues() Date: Mon, 16 Jul 2012 19:46:58 -0700 (PDT) Organization: http://groups.google.com Lines: 39 Message-ID: <88a2fb2e-b6b6-441a-ab35-4bd5481ea59c@googlegroups.com> References: <34011151-6528-4f4c-815c-df9e8353cb71@googlegroups.com> <_40Nr.24747$cE7.24028@newsfe13.iad> NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1342493578 8889 127.0.0.1 (17 Jul 2012 02:52:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 17 Jul 2012 02:52:58 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:16058 On Monday, July 16, 2012 4:47:53 PM UTC-7, Jeff Higgins wrote: > Daniel Pitts wrote: >> Higgins wrote: >>> clusardi2k... wrote: > >>> Hello, can anyone give me a simple/complete example to replace > >>> jLst.getSelectedValues() below using jLst.getSelectedValuesList(). > >>> > >>> Object str_array []; > >>> > >>> if ( !jLst.isSelectionEmpty() ) > >>> { > >>> str_array = jLst.getSelectedValues(); > >>> > >>> System.out.println("Selected: " + str_array[0]); > >>> } > >> I think the java.util.List<E> interface has a method to return an array. > >> > > Indeed it does, but that is terrible advice. > > str_array = jLst.getSelectedValuesList().toArray(); > > Is that much better? > > > > > jList.getSelectedValuesList().get(0) is equivalent to > > jList.getSelectedValues()[0]; > > What's better is System.out.println("Selected: " + jLst.getSelectedValuesList().get(0)); with appropriate guards against NPE. Unless, as markspace points out, the OP actually needs an array for reasons not in the original post. -- Lew