The [] gives you more options...

When you use the dot operator, the thing on the left can be only a Map or a bean, and the thing on the right must follow Java naming rules for identifiers. But with the [ ], the thing on the left can also be a List or an array (of any type). That also means the thing on the right can be a number, or anything that resolves to a number, or an identifier that doesn’t fit the Java naming rules. For example, you might have a Map key that’s a String with dots in the name (“com.foo.trouble”).

  1. If the expression has a variable followed by a bracket [ ], the left-hand variable can be a Map, a bean, a List, or an array.

    image with no caption
  2. If the thing inside the brackets is a String literal (i.e., in quotes), it can be a Map key or a bean property, or an index into a List or array.

    image with no caption
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset