Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: Using getSelectedValuesList() instead of the deprecated getSelectedValues() Date: Tue, 17 Jul 2012 07:38:29 -0400 Organization: A noiseless patient Spider Lines: 43 Message-ID: References: <34011151-6528-4f4c-815c-df9e8353cb71@googlegroups.com> <_40Nr.24747$cE7.24028@newsfe13.iad> <88a2fb2e-b6b6-441a-ab35-4bd5481ea59c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 17 Jul 2012 11:36:05 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="dbab98bdd12434f87ad48400212f412c"; logging-data="23814"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18M4SUxteUYZMQBFzDA2p77mivqOYcFtnc=" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20120613 Icedove/3.0.11 In-Reply-To: <88a2fb2e-b6b6-441a-ab35-4bd5481ea59c@googlegroups.com> Cancel-Lock: sha1:eit738FHrmn4cQEPdOQ7cIZ5404= Xref: csiph.com comp.lang.java.programmer:16065 On 07/16/2012 10:46 PM, Lew wrote: > 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. >> >> The XML escapes are distracting. I wish I knew how to get my newsreader how to restore them to characters. >> > 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. >