Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31363 > unrolled thread

unable to understand some code

Started byVish <vishal.kaushish@gmail.com>
First post2015-03-24 23:56 -0700
Last post2015-03-25 08:11 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  unable to understand some code Vish <vishal.kaushish@gmail.com> - 2015-03-24 23:56 -0700
    Re: unable to understand some code Jeff Higgins <jeff@invalid.invalid> - 2015-03-25 08:11 -0400

#31363 — unable to understand some code

FromVish <vishal.kaushish@gmail.com>
Date2015-03-24 23:56 -0700
Subjectunable to understand some code
Message-ID<5a671b9c-fd76-46bd-92f7-0480c162c5dd@googlegroups.com>
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<String> testSuites = new ArrayList<String>();
		
		----
		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
	  
	  

[toc] | [next] | [standalone]


#31364

FromJeff Higgins <jeff@invalid.invalid>
Date2015-03-25 08:11 -0400
Message-ID<meu8mo$abv$1@dont-email.me>
In reply to#31363
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<String> testSuites = new ArrayList<String>();
> 		
> 		----
> 		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();
     }

   }

}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web