{"id":27378,"date":"2015-09-21T15:00:27","date_gmt":"2015-09-21T12:00:27","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=27378"},"modified":"2019-03-29T14:29:56","modified_gmt":"2019-03-29T12:29:56","slug":"groovy-array-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/","title":{"rendered":"Groovy Array Example"},"content":{"rendered":"<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt> <a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt> <a href=\"#array_declaration\">2. Array Declaration<\/a><\/dt>\n<dt> <a href=\"#access_array_items\">3. Access Array Items<\/a><\/dt>\n<dt> <a href=\"#add_item_exception\">4. Add Item Exception<\/a><\/dt>\n<dt> <a href=\"#array_length\">5. Array Length<\/a><\/dt>\n<dt> <a href=\"#array_min_max_value\">6. Array Min &amp; Max Value<\/a><\/dt>\n<dt> <a href=\"#remove_item\">7. Remove Item<\/a><\/dt>\n<dt> <a href=\"#array_ordering\">8. Array Ordering<\/a><\/dt>\n<dt> <a href=\"#array_lookup\">9. Array Lookup<\/a><\/dt>\n<dt> <a href=\"#conversion\">10. Conversion<\/a><\/dt>\n<dt> <a href=\"#conclusion\">11. Conclusion<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>In previous tutorials, we have mentioned about <a href=\"http:\/\/examples.javacodegeeks.com\/core-java\/groovy-list-example\/\">Groovy List<\/a> and provided lots of examples. In this tutorial, I will show you how to use Groovy arrays. Even if array and list seems to be same, they have differences in common. For example, arrays have fixed size while lists have dynamic size that means you can add item as much as you can after initialization of the list. If you try to add item to array with a size bigger than initial size of the array after initialization, you will get <a href=\"http:\/\/docs.groovy-lang.org\/latest\/html\/api\/groovy\/lang\/MissingMethodException.html\" target=\"_blank\" rel=\"noopener noreferrer\">MissingMethodException<\/a> or <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/ArrayIndexOutOfBoundsException.html\" target=\"_blank\" rel=\"noopener noreferrer\">ArrayIndexOutOfBoundsException<\/a>. After some theory, let&#8217;s see some Groovy arrays in action.\n<\/p>\n<h2><a name=\"array_declaration\"><\/a>2. Array Declaration<\/h2>\n<p>In Groovy, you can declare array in Java style or Groovy style. Let&#8217;s have a look at following example for array declaration.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayDeclaration.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayDeclaration {\n\n\tstatic main(args) {\n\t\tdef birds = new String[3]\n\t\tbirds[0] = \"Parrot\"\n\t\tbirds.putAt(1, \"Cockatiel\")\n\t\tbirds[2] = \"Pigeon\"\n\t\t\n\t\tprintln birds \/\/ [Parrot, Cockatiel, Pigeon]\n\t\t\n\t\tdef birdArr = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[] \/\/ You say that this is an array of Strings\n\t\t\n\t\tprintln birdArr \/\/ [Parrot, Cockatiel, Pigeon]\n\t}\n\n}\n<\/pre>\n<p>As you can see in the example, you can declare an array with a size, and then you can put elements in different ways in Java style. In second example, the array is directly declared with initial values. Also, it has been casted to the String that means this array has elements of type String.<\/p>\n<h2><a name=\"access_array_items\"><\/a>3. Access Array Items<\/h2>\n<p>In Groovy, you can access array item by using square bracket with an index (<code>[index]<\/code>) or using <code>getAt(index)<\/code> function. Let&#8217;s have a look at following example to see what is going on.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayAccessItem.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayAccessItem {\n\n\tstatic main(args) {\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tprintln birds[0] \/\/ Parrot\n\t\tprintln birds[2] \/\/ Pigeon\n\t\tprintln birds.getAt(1) \/\/ Cockatiel\n\t\t\n\t\tprintln birds[-1] \/\/ Pigeon\n\t\tprintln birds[-3] \/\/ Parrot\n\t}\n\n}\n<\/pre>\n<p>As you may already know, it is easy to understand the case on <code>line 09<\/code>, <code>line 10<\/code> and <code>line 11<\/code>. They are simple operations to get items on specific index. What about on <code>line 13<\/code>? Why we use negative index? It is simple, when you use negative index, it will be accessed from the end of the array with 1 based index. When you say <code>-1<\/code> it means the first element from the end. And in same way, when you say <code>-3<\/code>, it means third element from the end.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2><a name=\"add_item_exception\"><\/a>4. Add Item Exception<\/h2>\n<p>As we said earlier, If you try to add items to an array with a bigger size than the fixed length, you will get an exception as in the example below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyAddItemException.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyAddItemException {\n\n\tstatic main(args) {\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tbirds &lt;&lt; \"Eagle\" \/\/ MissingMethodException\n\t\t\n\t\tbirds.putAt(3, \"Owl\") \/\/ ArrayIndexOutOfBoundsException\n\t}\n\n}\n<\/pre>\n<p>On <code>line 08<\/code>, the method &lt;&lt; belongs to list, that is why we got <code>MissingMethodException<\/code>. On <code>line 10<\/code> we have exception due to overflow the size of the array wit a size 3.<\/p>\n<h2><a name=\"array_length\"><\/a>5. Array Length<\/h2>\n<p>In Java, you can use <code>size()<\/code> method for the list, and <code>length<\/code> method for the arrays in order to get actual size of the object. In Groovy, it has been simplified and you can use size method for both arrays or lists. You can see simple example below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayLength.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayLength {\n\n\tstatic main(args) {\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tprintln birds.length \/\/ 3\n\t\t\n\t\tprintln birds.size() \/\/ 3\n\t}\n\n}\n<\/pre>\n<h2><a name=\"array_min_max_value\"><\/a>6. Array Min &amp; Max Value<\/h2>\n<p>Let say that, you have array of numbers. You can easily find the minimum and maximum value by using the <code>min()<\/code> and <code>max()<\/code> functions over arrays as below.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayMinMax.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayMinMax {\n\n\tstatic main(args) {\n\t\t\n\t\tdef numbers = [32, 44, 12, 9, 100, 180]\n\t\t\n\t\tprintln numbers.max() \/\/ 180\n\t\tprintln numbers.min() \/\/ 9\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tprintln birds.max { it.size() } \/\/ Cockatiel\n\t\tprintln birds.min { it.size() } \/\/ Parrot\n\t}\n\n}\n\n<\/pre>\n<p>On <code>line 09<\/code> and <code>line 10<\/code> you can easily understand the case but, the trick on <code>line 14<\/code> and <code>line 15<\/code> is, the minimum and maximum value is determined by the length of the current string value. Let say that you are iterating to find minimum and maximum value, <code>it<\/code> means current value in the array.<\/p>\n<h2><a name=\"remove_item\"><\/a>7. Remove Item<\/h2>\n<p>Removing item here is not actually removing item from array. It is something like assign the array with one item removed version to another variable. Let see it in action.[ulp id=&#8217;kHqyxwGNoyzYAfPN&#8217;]<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayRemoveItem.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayRemoveItem {\n\n\tstatic main(args) {\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tdef birdsWithoutParrot = birds - \"Parrot\"\n\t\t\n\t\tprintln birds \/\/ [Parrot, Cockatiel, Pigeon]\n\t\t\n\t\tprintln birdsWithoutParrot \/\/ [Cockatiel, Pigeon]\n\t}\n\n}\n<\/pre>\n<p>As you can see on <code>line 09<\/code>, we are using subtracting method to remove one item and assign final version to another variable. It is not removed from the original array actually as you can see on <code>line 11<\/code>. However, you can see another array without &#8220;Parrot&#8221; on <code>line 13<\/code>.<\/p>\n<h2><a name=\"array_ordering\"><\/a>8. Array Ordering<\/h2>\n<p>If you are interacting with collections, you may need to do ordering operations time to time. For example, you may want to reverse array, or sort the array items. You can see following example to see how it looks like.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayOrdering.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayOrdering {\n\n\tstatic main(args) {\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tprintln birds.reverse() \/\/ [Pigeon, Cockatiel, Parrot]\n\t\t\n\t\tprintln birds.sort() \/\/ [Cockatiel, Parrot, Pigeon]\n\t}\n\n}\n<\/pre>\n<p>In above example, array is reversed and items printed on the screen in reverse way on <code>line 09<\/code>. Also, array sorted in alphabetical order by using <code>sort()<\/code> function. You can see it on <code>line 11<\/code><\/p>\n<h2><a name=\"array_lookup\"><\/a>9. Array Lookup<\/h2>\n<p>You can perform lookup operations on arrays. In following example we will reverse every item text and also we will find an item by matching a provided regex. Let&#8217;s do it.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayLookup.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayLookup {\n\n\tstatic main(args) {\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tdef revertedBirds = birds.collect { it.reverse() }\n\t\t\n\t\tprintln revertedBirds \/\/ [torraP, leitakcoC, noegiP]\n\t\t\n\t\tdef founded = birds.find { it =~ \/Cockatiel\/ }\n\t\t\n\t\tprintln founded \/\/ Cockatiel\n \t}\n\n} \n<\/pre>\n<p>On <code>line 11<\/code>, we have iterated by using <code>collect<\/code> function and reversed each item by using <code>reverse()<\/code> function. Again, <code>it<\/code> stands for the current item in the code. On <code>line 13<\/code>, we have used <code>find<\/code> function to find specific item by using regular expression.<\/p>\n<h2><a name=\"conversion\"><\/a>10. Conversion<\/h2>\n<p>You can also convert array to list in Groovy easily. You can see following example for simple usage.<\/p>\n<p><span style=\"text-decoration: underline\"><em>GroovyArrayConversion.groovy<\/em><\/span><\/p>\n<pre class=\"brush:groovy\">package com.javacodegeeks.groovy.array\n\nclass GroovyArrayConversion {\n\n\tstatic main(args) {\n\t\t\n\t\tdef birds = [\"Parrot\", \"Cockatiel\", \"Pigeon\"] as String[]\n\t\t\n\t\tdef birdList = birds.toList()\n\t\t\n\t\tprintln birdList.class.name \/\/ java.util.ArrayList\n\t\t\n\t\tdef birdsAgain = birdList as String[]\n\t\t\n\t\tprintln birdsAgain.class.name \/\/ [Ljava.lang.String;\n \t}\n\n}\n<\/pre>\n<p>On <code>line 09<\/code>, we have used toList function to convert array to list. When you check the class name of <code>birdList<\/code> you will see it is instance of <code>java.util.ArrayList<\/code>. As you can guess, you can convert list to array. Check out line 13 and it is easily casted to array. You can check the class name on <code>line 15<\/code>, and you will see it is <code>[Ljava.lang.String;<\/code><\/p>\n<h2><a name=\"conclusion\"><\/a>11. Conclusion<\/h2>\n<p>To sum up, array and list has same properties in common, but there are major differences between array and list. One of the well known difference is array has fixed size and list has dynamic size in usage. If you try to add more item bigger than the array size, you will get exception. Additionally, you can perform many operations on array like list.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of the project here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/GroovyArrayExample.zip\"><strong>GroovyArrayExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove Item 8. Array Ordering 9. Array Lookup 10. Conversion 11. Conclusion 1. Introduction In previous tutorials, we have mentioned about Groovy List and provided lots of examples. In &hellip;<\/p>\n","protected":false},"author":56,"featured_media":24987,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1216],"tags":[176],"class_list":["post-27378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-groovy","tag-arrays-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Groovy Array Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Groovy Array Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-21T12:00:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-29T12:29:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Huseyin Babal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@huseyinbabal\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Huseyin Babal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\"},\"author\":{\"name\":\"Huseyin Babal\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237\"},\"headline\":\"Groovy Array Example\",\"datePublished\":\"2015-09-21T12:00:27+00:00\",\"dateModified\":\"2019-03-29T12:29:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\"},\"wordCount\":909,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg\",\"keywords\":[\"arrays\"],\"articleSection\":[\"Groovy\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\",\"name\":\"Groovy Array Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg\",\"datePublished\":\"2015-09-21T12:00:27+00:00\",\"dateModified\":\"2019-03-29T12:29:56+00:00\",\"description\":\"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Groovy Array Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237\",\"name\":\"Huseyin Babal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg\",\"caption\":\"Huseyin Babal\"},\"description\":\"Huseyin Babal has deep experience in Full Stack Development since 2007. He is mainly developing applications with JAVA, Spring, PHP, NodeJS, AngularJS. He is also interested in DevOps Engineering since 2013 and using AWS, Heroku for Cloud deployment and playing with Docker and Consul for implementing infinite scalable systems. He likes to share his experience in public conferences and perform advanced workshops about Full Stack Development and Devops. He is the author of NodeJS in Action course in Udemy.\",\"sameAs\":[\"http:\/\/huseyinbabal.net\",\"https:\/\/www.linkedin.com\/in\/huseyinbabal\",\"https:\/\/x.com\/huseyinbabal\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/huseyin-babal\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Groovy Array Example - Java Code Geeks","description":"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/","og_locale":"en_US","og_type":"article","og_title":"Groovy Array Example - Java Code Geeks","og_description":"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove","og_url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-09-21T12:00:27+00:00","article_modified_time":"2019-03-29T12:29:56+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg","type":"image\/jpeg"}],"author":"Huseyin Babal","twitter_card":"summary_large_image","twitter_creator":"@huseyinbabal","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Huseyin Babal","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/"},"author":{"name":"Huseyin Babal","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237"},"headline":"Groovy Array Example","datePublished":"2015-09-21T12:00:27+00:00","dateModified":"2019-03-29T12:29:56+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/"},"wordCount":909,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg","keywords":["arrays"],"articleSection":["Groovy"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/","url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/","name":"Groovy Array Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg","datePublished":"2015-09-21T12:00:27+00:00","dateModified":"2019-03-29T12:29:56+00:00","description":"Table Of Contents 1. Introduction 2. Array Declaration 3. Access Array Items 4. Add Item Exception 5. Array Length 6. Array Min &amp; Max Value 7. Remove","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/groovy-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/groovy-array-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/"},{"@type":"ListItem","position":3,"name":"Groovy","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/"},{"@type":"ListItem","position":4,"name":"Groovy Array Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/a64b2fa737b82194b7dfc39117f4a237","name":"Huseyin Babal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/Huseyin-Babal-96x96.jpg","caption":"Huseyin Babal"},"description":"Huseyin Babal has deep experience in Full Stack Development since 2007. He is mainly developing applications with JAVA, Spring, PHP, NodeJS, AngularJS. He is also interested in DevOps Engineering since 2013 and using AWS, Heroku for Cloud deployment and playing with Docker and Consul for implementing infinite scalable systems. He likes to share his experience in public conferences and perform advanced workshops about Full Stack Development and Devops. He is the author of NodeJS in Action course in Udemy.","sameAs":["http:\/\/huseyinbabal.net","https:\/\/www.linkedin.com\/in\/huseyinbabal","https:\/\/x.com\/huseyinbabal"],"url":"https:\/\/examples.javacodegeeks.com\/author\/huseyin-babal\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/56"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=27378"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27378\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/24987"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=27378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=27378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=27378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}