🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #152960

ArrayList return w petli

#152960
From: LprzemekL
Date: Wed, 12 Oct 2011 19:37
43 lines
2574 bytes
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().
Technical Details
Message-ID: <dd1483fc-8c50-4b81-8df7-55af82a052fe@m5g2000vbe.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!m5g2000vbe.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!m5g2000vbe.googlegroups.com!not-for-mail
From: LprzemekL <zubertowicz@tenbit.pl>
Newsgroups: pl.comp.lang.java
Subject: ArrayList return w petli
Date: Wed, 12 Oct 2011 12:37:24 -0700 (PDT)
Organization: http://groups.google.com
Lines: 43
Message-ID: <dd1483fc-8c50-4b81-8df7-55af82a052fe@m5g2000vbe.googlegroups.com>
NNTP-Posting-Host: 109.243.49.119
Mime-Version: 1.0
X-Trace: posting.google.com 1318448244 18830 127.0.0.1 (12 Oct 2011 19:37:24 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 12 Oct 2011 19:37:24 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: m5g2000vbe.googlegroups.com; posting-host=109.243.49.119; posting-account=7L1DswoAAABpvfjY8Gr3MuPfsLeFwbMQ
User-Agent: G2/1.0
X-Google-Web-Client: true
X-Google-Header-Order: HUALESNKRC
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2,gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit