Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: unable to understand some code Date: Wed, 25 Mar 2015 08:11:47 -0400 Organization: A noiseless patient Spider Lines: 82 Message-ID: References: <5a671b9c-fd76-46bd-92f7-0480c162c5dd@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 25 Mar 2015 12:12:08 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="c50a9e5d554cfaba13eda1c71e805135"; logging-data="10623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nuGFcM7/uwdFYvOAXk9YkNol2pQHIPLg=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 In-Reply-To: <5a671b9c-fd76-46bd-92f7-0480c162c5dd@googlegroups.com> Cancel-Lock: sha1:tLmjlGyshSKBNQ4Yx6OiZxOFPWo= Xref: csiph.com comp.lang.java.programmer:31364 On 03/25/2015 02:56 AM, Vish wrote: > public class Test > { > private final static Class[] TEST_CLASSES = new Class[]{}; > private static final String DEFAULT_OS = "window"; > private static final String DEFAULT_BROWSER = "firefox"; > > public static void main(String[] args) > { > if (args.length > 0) { > for (int i = 0; i < args.length && args[i].split("=").length == 2; i++) { > String key = args[i].split("=")[0]; > String value = args[i].split("=")[1]; > System.setProperty(key, value); > } > } > > System.out.println("window: " + System.getProperty("window", DEFAULT_OS)); > > > List testSuites = new ArrayList(); > > ---- > some other code > ---- > } > > I am not able to understand below things from above code, Please help me to understand the below > > 1. Mentioned inside the for loop, (i < args.length && args[i].split("=").length == 2), what does mean "args[i].split("=").length == 2" > > 2. String key = args[i].split("=")[0]; > String value = args[i].split("=")[1]; > in 2nd point seems like array 1st and 2nd index for [0] and [1] but confusing > > What does mean args[i].split("=")[0]; and args[i].split("=")[1]; I am confused with [0] and [1] written in the end > > > Look in the Javadoc for the documentation for java.lang.String split(String regex) method. Arrays have a public int field (length) which holds the count of the array's entries. == is the Java equality operator. Java array indexes are zero based. package scratch; public class Test { public static void main(String[] args) { System.out.println(args.length + " : number of Strings contained by args\n"); for(String arg : args) { System.out.println(arg); String[] temp; temp = arg.split("="); int count = temp.length; System.out.println(count + " : number of Strings contained by temp"); if(temp.length == 2) { System.out.println("String array temp contains two entries"); } else { System.out.println("String array temp does not contain two entries"); } for(String s : temp) { System.out.println(s); } System.out.println(); } } }