Article View: pl.comp.lang.java
Article #152962Re: ArrayList return w petli
From: Kacper Szymański
Date: Thu, 13 Oct 2011 08:31
Date: Thu, 13 Oct 2011 08:31
45 lines
3743 bytes
3743 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().
Hej, spróbuj nadpisać metodę toString()
Technical Details
Message-ID:
<49c34366-bf89-4792-a6c6-c9f6bfa57040@11g2000yqk.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!11g2000yqk.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!newsfeed2.atman.pl!newsfeed.atman.pl!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!11g2000yqk.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:31:43 -0700 (PDT) Organization: http://groups.google.com Lines: 57 Message-ID: <49c34366-bf89-4792-a6c6-c9f6bfa57040@11g2000yqk.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 1318494793 17196 127.0.0.1 (13 Oct 2011 08:33:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Oct 2011 08:33:13 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 11g2000yqk.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