{"id":128547,"date":"2024-11-22T18:48:54","date_gmt":"2024-11-22T16:48:54","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=128547"},"modified":"2024-11-19T10:19:30","modified_gmt":"2024-11-19T08:19:30","slug":"insert-a-number-into-a-sorted-array-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html","title":{"rendered":"Insert a Number Into a Sorted Array Example"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>Manipulating sorted arrays is a common requirement in Java applications that maintain ordered collections either for efficient retrieval or ranking. In this example, I will show two methods to insert a number into a sorted array with the following steps:<\/p>\n<ol class=\"wp-block-list\">\n<li>Find the insertion point via <a href=\"https:\/\/en.wikipedia.org\/wiki\/Binary_search\" target=\"_blank\" rel=\"noreferrer noopener\">binary search<\/a>. The binary search algorithm has <code>O(log n)<\/code> <a href=\"https:\/\/www.w3schools.com\/dsa\/dsa_timecomplexity_theory.php\" target=\"_blank\" rel=\"noreferrer noopener\">time complexity<\/a>.<\/li>\n<li>Insert the element at the insertion position. It has <code>O(n)<\/code> time and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Space_complexity\">space complexity<\/a><\/li>\n<\/ol>\n<h2 class=\"wp-block-heading\">2. Setup<\/h2>\n<p>In this step, I will create a simple Java project in Eclipse IDE with the Junit 5 library.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/project_array.jpg\"><img decoding=\"async\" width=\"471\" height=\"342\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/project_array.jpg\" alt=\"Sorted Array insert Number Project\" class=\"wp-image-128558\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/project_array.jpg 471w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/project_array-300x218.jpg 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 1. Sorted Array Insert Number Project<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\"><a name=\"step3\"><\/a>3. Array Sorted Insert Number Class<\/h2>\n<p>In this step, I will create a <code>DemoInsertArray.java<\/code> class with two methods: <code>insert_via_Array<\/code> and <code>insert_via_List<\/code>. Both methods have the same arguments: <code>final int[] sortedArray, final int newNumber<\/code>. The <code>insert_via_List<\/code> method uses <code>sortedList.add(insertIdx, newNumber)<\/code> to add the new number at the desired position while <code>insert_via_Array<\/code> method populates the new array with the following steps:<\/p>\n<ol class=\"wp-block-list\">\n<li>Copy the original sorted array from the beginning to the insertion point to the new array.<\/li>\n<li>Add the new element at the found insertion position.<\/li>\n<li>Copy the remaining elements from the original array into the new array right after the added number.<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline\"><em>DemoInsertArray.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[11,18,20,22,24,30,35,39,41]\">package org.jcg.zheng;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\n\npublic class DemoInsertArray {\n\n\tpublic int[] insert_via_Array(final int[] sortedArray, final int newNumber) {\n\t\tint insertIdx = Arrays.binarySearch(sortedArray, newNumber);\n\t\tif (insertIdx &lt; 0) {\n\t\t\tinsertIdx = -(insertIdx + 1);\n\t\t}\n\n\t\tint existingArrayLength = sortedArray.length;\n\t\t\/\/ create a new array with bigger size\n\t\tint[] newArray = new int[existingArrayLength + 1];\n\n\t\tSystem.arraycopy(sortedArray, 0, newArray, 0, insertIdx);\n\n\t\tnewArray[insertIdx] = newNumber;\n\n\t\tSystem.arraycopy(sortedArray, insertIdx, newArray, insertIdx + 1, existingArrayLength - insertIdx);\n\n\t\treturn newArray;\n\t}\n\n\tpublic int[] insert_via_List(final int[] sortedArray, final int newNumber) {\n\t\tList&lt;Integer&gt; sortedList = new ArrayList&lt;&gt;();\n\t\tfor (int n : sortedArray) {\n\t\t\tsortedList.add(n);\n\t\t}\n\n\t\tint insertIdx = Collections.binarySearch(sortedList, newNumber);\n\t\tif (insertIdx &lt; 0) {\n\t\t\tinsertIdx = -(insertIdx + 1);\n\t\t}\n\t\tsortedList.add(insertIdx, newNumber);\n\n\t\treturn sortedList.stream().mapToInt(n -&gt; n).toArray();\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 11: use <code>Arrays.binarySearch<\/code> to find the insertion position. The time complexity is <code>O(log n)<\/code>.<\/li>\n<li>Line 18: create a new Array. The space complexity is <code>O(n)<\/code>.<\/li>\n<li>Line 20: use <code>System.arraycopy<\/code> to copy the original array from the beginning to the insertion position.<\/li>\n<li>Line 22: set the <code>newNumber<\/code> at the inserting position of the new array.<\/li>\n<li>Line 24: use <code>System.arraycopy<\/code> to copy the original array after the insertion position to the new array.<\/li>\n<li>Line 30, 35, 39, 41: similar to the <code>insert_via_Array<\/code> method, but it finds the insertion position via <code>Collections.binarySearch<\/code> and adds the new number via <code>sortedList.add(insertIdx, newNumber)<\/code>. It is easier as no manual shifting is needed.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.2. Test Array Sorted Insert Number<\/h3>\n<p>In this step, I will create a <code>DemoInsertArrayTest.java<\/code> test class to test both methods defined in <a href=\"#step3\">step 3<\/a>. Figure 2 shows that the <code>insert_via_Array<\/code> method is faster than the <code>insert_via_List<\/code> method.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>DemoInsertArrayTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[18,19,22,23,28,29,32,33]\">package org.jcg.zheng;\n\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n\nimport java.util.stream.IntStream;\n\nimport org.junit.jupiter.api.Test;\n\nclass DemoInsertArrayTest {\n\n\tprivate DemoInsertArray testClass = new DemoInsertArray();\n\n\tprivate int[] sortedArray = IntStream.range(1, 1000).toArray();\n\tprivate int newNumber = 666;\n\n\t@Test\n\tvoid test_insert_via_Array() {\n\t\tassertEquals(999, sortedArray.length);\n\t\tassertEquals(667, sortedArray[666]);\n\n\t\tint[] updatedSortedArray = testClass.insert_via_Array(sortedArray, newNumber);\n\t\tassertEquals(1000, updatedSortedArray.length);\n\t\tassertEquals(666, updatedSortedArray[666]);\n\t}\n\n\t@Test\n\tvoid test_insert_via_List() {\n\t\tassertEquals(999, sortedArray.length);\n\t\tassertEquals(667, sortedArray[666]);\n\n\t\tint[] updatedSortedArray = testClass.insert_via_List(sortedArray, newNumber);\n\t\tassertEquals(1000, updatedSortedArray.length);\n\t\tassertEquals(666, updatedSortedArray[666]);\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 18, 19, 28, 29: the sorted array length and 666 position value before the insertion.<\/li>\n<li>Line 22, 23, 32, 32: the sorted array length and 666 position value after the insertion.<\/li>\n<\/ul>\n<p>Execute the Junit tests and capture the testing results:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/junitTest.jpg\"><img decoding=\"async\" width=\"472\" height=\"277\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/junitTest.jpg\" alt=\"Sorted Array Insert Number Tests\" class=\"wp-image-128562\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/junitTest.jpg 472w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/junitTest-300x176.jpg 300w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 2. Insert Sorted Array Test Results<\/figcaption><\/figure>\n<\/div>\n<p>As Figure 2 shows, <code>test_insert_via_Array<\/code> took <code>0.000<\/code> seconds which is faster than the <code>test_insert_via_List<\/code>&#8216;s <code>0.016<\/code> seconds.<\/p>\n<h2 class=\"wp-block-heading\">4. Conclusion<\/h2>\n<p>Inserting a number into a sorted array should be done efficiently for applications that maintain an ordered collection. Here are two application examples:<\/p>\n<ul class=\"wp-block-list\">\n<li>A ranked leaderboard that shows the leader based on the score.<\/li>\n<li>A priority scheduler that tasks are added constantly and then inserted into the ordered priority position.<\/li>\n<\/ul>\n<p>In this example, I showed two methods to insert a number into a sorted array. Both use the binary search to find the insert position but the <code>insert_via_Array<\/code> method uses <code>System.arraycopy<\/code> while the <code>insert_via_List<\/code> method uses <code>sortedList.add(insertIdx, newNumber)<\/code> to populate the new sorted array.<\/p>\n<h2 class=\"wp-block-heading\">5. Download<\/h2>\n<p>This was an example of a Java project which inserted a number into a sorted array.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/InsertArrayDemo.zip\"><strong>Insert a Number Into a Sorted Array Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Manipulating sorted arrays is a common requirement in Java applications that maintain ordered collections either for efficient retrieval or ranking. In this example, I will show two methods to insert a number into a sorted array with the following steps: Find the insertion point via binary search. The binary search algorithm has O(log &hellip;<\/p>\n","protected":false},"author":128892,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[2840],"class_list":["post-128547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-array"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Insert a Number Into a Sorted Array Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about array sorted insert number? Then check out our detailed examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Insert a Number Into a Sorted Array Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about array sorted insert number? Then check out our detailed examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-22T16:48:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-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=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\"},\"headline\":\"Insert a Number Into a Sorted Array Example\",\"datePublished\":\"2024-11-22T16:48:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html\"},\"wordCount\":485,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"array\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html\",\"name\":\"Insert a Number Into a Sorted Array Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2024-11-22T16:48:54+00:00\",\"description\":\"Interested to learn more about array sorted insert number? Then check out our detailed examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/insert-a-number-into-a-sorted-array-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Insert a Number Into a Sorted Array Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mary-zheng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Insert a Number Into a Sorted Array Example - Java Code Geeks","description":"Interested to learn more about array sorted insert number? Then check out our detailed examples.","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:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html","og_locale":"en_US","og_type":"article","og_title":"Insert a Number Into a Sorted Array Example - Java Code Geeks","og_description":"Interested to learn more about array sorted insert number? Then check out our detailed examples.","og_url":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-11-22T16:48:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html"},"author":{"name":"Mary Zheng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5"},"headline":"Insert a Number Into a Sorted Array Example","datePublished":"2024-11-22T16:48:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html"},"wordCount":485,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["array"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html","url":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html","name":"Insert a Number Into a Sorted Array Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2024-11-22T16:48:54+00:00","description":"Interested to learn more about array sorted insert number? Then check out our detailed examples.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/insert-a-number-into-a-sorted-array-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Insert a Number Into a Sorted Array Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","caption":"Mary Zheng"},"description":"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.","sameAs":["https:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/mary-zheng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128892"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=128547"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128547\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=128547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=128547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=128547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}