Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Thu, 25 Aug 2011 00:49:08 -0500 Date: Wed, 24 Aug 2011 22:49:07 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? References: <4e55dd30$0$7613$9b4e6d93@newsspool1.arcor-online.net> In-Reply-To: <4e55dd30$0$7613$9b4e6d93@newsspool1.arcor-online.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 34 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-vKmph77+WF0UCuM6p+aQNayMbrmjuAkLu/SynmhhDjw0RZu8xGdH+jijuK8s6jkRji116UGeAlOFsuU!MzISncUAQ7qveQq2NvVKSlfJtbHz/OyOPcqSWlX48e++NcDsML8XWwYwUluWBmMZmsN/G3b7ShsG!s/mUUQh65ASYBnzoCg76ZSQ6B+gk5Ayz2QeTLHiF0jk= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2667 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7364 On 8/24/11 10:27 PM, Gunter Hansen wrote: > Assume I split a text line with a command like: > > String[] part = line.split("\\s+"); > > Ok, fine, but how is the opposite command? > Keep in mind that the delimiter between the joined slots of the target string should be one blank. > > Moreover: Can I join e.g. only slots [3],...,[MAX]? > > So I need a command similar to: > > String joined = part[3,MAX].join(' '); > > How ca I achieve this? > > If this is not possible directly then maxbe with a work around? I am surprised the feature doesn't exist in the JDK; in .NET there's a String.Join() method that does exactly what you're asking about. But AFAIK, it doesn't. That said, it's trivial to write one yourself, or you could use the Apache StringUtils library (as this top-three Bing hit mentions in two different replies: http://stackoverflow.com/questions/187676/string-operations-in-java …funny what a web search will turn up, if you just do the search). And I have to admit, I think Java's take on the "split" function is pretty cool, what with regex support and all (which .NET doesn't provide, not as a String.Split() feature anyway). So IMHO Java wins this particular feature comparison. :) Pete