Article View: pl.comp.lang.java
Article #152961Re: ArrayList return w petli
From: Kacper Szymański
Date: Thu, 13 Oct 2011 08:30
Date: Thu, 13 Oct 2011 08:30
45 lines
3659 bytes
3659 bytes
On 12 Paź, 21:37, LprzemekL <zubertow...@tenbit.pl> wrote:
> Hej,
> Mam taka metode, ktora zwraca wynik ping:
>
> int numLines = 0;
>
> public String getPing(String result, int numLines, int arraySize,
> String result1, String result2) {
> String line = null;
> ArrayList<String> arrayList = new ArrayList<String>();
> try {
> Process p = Runtime.getRuntime().exec("ping -n 2 " + result);
> BufferedReader input = new BufferedReader(new
> InputStreamReader(p.getInputStream()));
>
> while ((line = input.readLine()) != null) {
> System.out.println(line); // pomocne tylko podczas analizy
> arrayList.add(numLines, line);
> numLines++;
> }
> arraySize = arrayList.size();
> result = arrayList.get(1);
> result1 = arrayList.get(2);
> result2 = arrayList.get(3);
> input.close();
>
> } catch (Exception err) {
> err.printStackTrace();
> return "ErrorList";
> }
> return result + result1 + result2;
> }
>
> Wynik pozniej bedzie wyrzucony na etykiete Label, komponent GWT.
> Pytanie: jak uzyskac taki efekt, zeby wynik wyrzucany byl z automatu
> (wiersz po wierszu) a nie tak jak w sytucji powyzszej, gdzie dodaje
> manualnie result, result1, result2, ...
> W tej chwili, to nie jest dobre rozwiazanie, gdyz recznie musze
> wybierac alementy z ArrayList a chcialbym, zeby to bylo robione z
> automatu (w jakiejs petli) i wyrzucane (cos z stylu result +
> numLines).
> Obiekt arraySize bedzie mial rozny rozmiar w zaleznosci od "ping -n X
> " + result, gdzie result to jest textBox.getText().
Nadpisz metodę toString()
Technical Details
Message-ID:
<ed3c17e3-220e-49d9-b066-729a04824206@s14g2000vbj.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.uni-stuttgart.de!news.belwue.de!news.osn.de!diablo2.news.osn.de!feeds.phibee-telecom.net!feeder.news-service.com!postnews.google.com!s14g2000vbj.googlegroups.com!not-for-mailReferences:
<dd1483fc-8c50-4b81-8df7-55af82a052fe@m5g2000vbe.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.uni-stuttgart.de!news.belwue.de!news.osn.de!diablo2.news.osn.de!feeds.phibee-telecom.net!feeder.news-service.com!postnews.google.com!s14g2000vbj.googlegroups.com!not-for-mail From: Kacper Szymański <kacper.szymanski1988@gmail.com> Newsgroups: pl.comp.lang.java Subject: Re: ArrayList return w petli Date: Thu, 13 Oct 2011 01:30:04 -0700 (PDT) Organization: http://groups.google.com Lines: 57 Message-ID: <ed3c17e3-220e-49d9-b066-729a04824206@s14g2000vbj.googlegroups.com> References: <dd1483fc-8c50-4b81-8df7-55af82a052fe@m5g2000vbe.googlegroups.com> NNTP-Posting-Host: 83.17.6.74 Mime-Version: 1.0 X-Trace: posting.google.com 1318494979 19272 127.0.0.1 (13 Oct 2011 08:36:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Oct 2011 08:36:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s14g2000vbj.googlegroups.com; posting-host=83.17.6.74; posting-account=90ZfRAoAAAAPS5nN40ZMuXlauUQFwaEX User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKUARELSC X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1,gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit