{"id":19291,"date":"2020-07-10T15:52:20","date_gmt":"2020-07-10T22:52:20","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=19291"},"modified":"2023-12-01T03:53:47","modified_gmt":"2023-12-01T11:53:47","slug":"java-bubble-sort","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/","title":{"rendered":"Java Bubble Sort: A Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Write a Java Bubble Sort<\/h2>\n\n\n\n<p>When programmers talk about bubble sorts, they are not talking about the water bubbles that you\u2019ve probably blown at some point in your life. They are talking about a sorting algorithm that is used to order a list of items.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about bubble sorts and how they work. We\u2019ll go on to implement a bubble sort using Java so that you can understand how this algorithm translates to code. Without further ado, let\u2019s dive into Java bubble sorts!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Java Bubble Sort?<\/h2>\n\n\n\n<p>A bubble sort is an algorithm that sorts values by comparing adjacent elements and swapping them if they appear in the wrong order.<br><\/p>\n\n\n\n<p>This process repeats until every item in a list is ordered correctly. Bubble sorts can be used to sort a list either in ascending or descending order.<br><\/p>\n\n\n\n<p>Bubble sorts are the first sort taught in algorithms classes. This is because they are easier to understand than other sorts, like an insertion sort or a selection sort, and provide a good introduction to sorting algorithms.<br><\/p>\n\n\n\n<p>Bubble sorts are most effective when the data is already almost sorted. However, if your data is not sorted at all, another type of sort may be more efficient.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do Bubble Sorts Work?<\/h2>\n\n\n\n<p>Before we start writing the code for a Java bubble sort, we have to first understand how this algorithm is implemented in practice.<br><\/p>\n\n\n\n<p>Consider the following list:<br><\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>5<\/td><td>9<\/td><td>2<\/td><td>7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Our bubble sort starts by comparing the first and second elements in our list.<br><\/p>\n\n\n\n<p>If the first element is greater than the second element, these elements swap positions. In this case, 5 is not greater than 9, so the elements stay in their same places.<br><\/p>\n\n\n\n<p>Then, our sort will compare the next two items in our list. 9 is greater than 2, and so these two numbers swap:<br><\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>5<\/td><td><strong>2<\/strong><\/td><td><strong>9<\/strong><\/td><td>7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This process repeats until every item in the list has been compared. In this case, there is one more comparison to perform: is 9 greater than 7? 9 is greater than 7, so these numbers swap:<br><\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>5<\/td><td>2<\/td><td>7<\/td><td>9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Our list is almost ordered. Once every item has been compared, the bubble sort will start over again until every element is sorted.<br><\/p>\n\n\n\n<p>5 is greater than 2, and so these numbers swap.<br><\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>2<\/td><td>5<\/td><td>7<\/td><td>9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Our list is now ordered correctly. Our bubble sort will keep comparing numbers until it gets to the end of the list, and then it will stop. That\u2019s all there is to a bubble sort. It&#8217;s definitely an easy algorithm to use once you get the hang of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Write a Java Bubble Sort<\/h2>\n\n\n\n<p>Knowing the theory is one thing but you came here to learn about Java bubble sorts. We\u2019d best discuss how to implement a bubble sort in Java.<br><\/p>\n\n\n\n<p>There are two types of bubble sorts:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Standard bubble sort<\/li>\n\n\n\n<li>Optimized bubble sort<\/li>\n<\/ul>\n\n\n\n<p>The standard bubble sort makes all possible comparisons even if an array is sorted. This increases the time it takes for the bubble sort to execute. This makes the sort less efficient.<br><\/p>\n\n\n\n<p>Optimized bubble sorts keep track of whether a list is sorted by using an additional variable. This allows us to stop our sort as soon as our list has been sorted.&nbsp;<br><\/p>\n\n\n\n<p>Let\u2019s start by writing a standard bubble sort.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Standard Bubble Sort<\/h3>\n\n\n\n<p>To start, we\u2019re going to import the Arrays library into our code. We\u2019ll use this later in our code to print out our list of sorted numbers to the console:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import java.util.Arrays;<\/pre><\/div>\n\n\n\n<p>Now that is out of the way, we can begin writing our algorithm.<br><\/p>\n\n\n\n<p>We\u2019ll start by defining a class called BubbleSort which stores the code for our Java program, and a function which performs our sort:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BubbleSort {\n\tvoid sortNumbers(int array[]) {\n\t\tint size = array.length;\n\t\tfor (int item = 0; item &lt; size - 1; item++) {\n\t\t\tfor (int j = 0; j &lt; size - item - 1; j++) {\n\t\t\t\tif (array[j] &gt; array[j + 1]) {\n\t\t\t\t\tint temporary = array[j];\n\t\t\t\t\tarray[j] = array[j + 1];\n\t\t\t\t\tarray[j + 1] = temporary;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<p>We have declared a function called <code>sortNumbers<\/code> which accepts a variable as a parameter. This function starts by calculating the size of the list of numbers we specify.<br><\/p>\n\n\n\n<p>Once this has been calculated, a for loop is initialized. This loop walks through every item in our array. We initialize another for loop which allows us to compare each item in the array.<br><\/p>\n\n\n\n<p>If the item on the left of a list is greater than the number on the right, the values are swapped. Otherwise, nothing happens.<br><\/p>\n\n\n\n<p>We perform this swap by assigning the value on the left to a variable called \u201ctemporary\u201d. We assign the value on the right the value that was on the left side of the comparison. Then, the value on the left is assigned the value of the temporary variable.<br><\/p>\n\n\n\n<p>If 6 and 5 were being compared, they would be swapped. So, our list would appear as: 6, 5.<br><\/p>\n\n\n\n<p>Our program doesn\u2019t do anything just yet. We haven\u2019t written a main program that calls our function and gives it a list to sort.<br><\/p>\n\n\n\n<p>Add the following code below the <code>sortNumbers<\/code> function in your code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>public static void main(String args[]) {\n\tint[] toSort = { 5, 9, 2, 7 };\n\tBubbleSort sortingAlgorithm = new BubbleSort();\n\tsortingAlgorithm.sortNumbers(toSort);\n\tSystem.out.println(Arrays.toString(toSort));\n}<\/pre><\/div>\n\n\n\n<p>We have declared a variable called toSort which stores the list of values we want to sort. We\u2019ve then declared an instance of the BubbleSort class called sortingAlgorithm, which we use on the next line of code to call the <code>sortNumbers<\/code> function. When this function is called, our list is sorted.<br><\/p>\n\n\n\n<p>Finally, we use the <code>Arrays.toString()<\/code> method to convert our list to a string so that we can print it out to the console. Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[2, 5, 7, 9]<\/pre><\/div>\n\n\n\n<p>We now have a sorted array!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Optimized Bubble Sort<\/h3>\n\n\n\n<p>There is a way to make our code more efficient. Right now, our sort continues until it has made all possible comparisons. This means that even if our array is sorted, the sort will keep going until those comparisons are complete.<br><\/p>\n\n\n\n<p>We can prevent this behavior by adding a new variable to our code. This will allow us to stop our sort if the list is swapped. Let\u2019s add this variable to our <code>sortNumbers<\/code> function from earlier:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class BubbleSort {\n\tvoid sortNumbers(int array[]) {\n\t\tint size = array.length;\n\t\tfor (int item = 0; item &lt; size - 1; item++) {\n\t\t\tboolean hasSwapped = false;\n\t\t\tfor (int j = 0; j &lt; size - item - 1; j++) {\n\t\t\t\tif (array[j] &gt; array[j + 1]) {\n\t\t\t\t\tint temporary = array[j];\n\t\t\t\t\tarray[j] = array[j + 1];\n\t\t\t\t\tarray[j + 1] = temporary;\n\t\t\t\t\thasSwapped = true;\n\t\t\t\t}\n\t\t\t}\nif (hasSwapped == false) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}<\/pre><\/div>\n\n\n\n<p>We\u2019ve made three changes to our code. Inside our first for loop we have declared a variable called \u201chasSwapped\u201d. This variable keeps track of whether a swap has been made. By default, this variable is set to \u201cfalse\u201d. If a swap is made, the value of this variable is set to \u201ctrue\u201d.<br><\/p>\n\n\n\n<p>At the end of our for loop, we have added an if statement to check if hasSwapped is equal to false. If no swaps have been made, the array is sorted. We use the \u201cbreak\u201d keyword to stop our loop from executing if hasSwapped is equal to false.<br><\/p>\n\n\n\n<p>Let\u2019s run our code using the main program we wrote earlier and see what happens:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[2, 5, 7, 9]<\/pre><\/div>\n\n\n\n<p>Our list has been sorted, but this time our algorithm is more efficient. If we used a larger list with more values to sort, the superior performance of this algorithm would be clearer. That\u2019s it, you have written an optimized bubble sort in Java!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Bubble sorts are used to sort lists in ascending or descending order. They work by comparing adjacent values and swapping them if they are in the wrong order.<br><\/p>\n\n\n\n<p>There are two types of bubble sort: standard and optimized. Standard bubble sorts perform a predefined number of swaps whereas optimized bubble sorts only keep sorting until a list is sorted.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to start writing bubble sorts in Java like an expert!<\/p>\n","protected":false},"excerpt":{"rendered":"How to Write a Java Bubble Sort When programmers talk about bubble sorts, they are not talking about the water bubbles that you\u2019ve probably blown at some point in your life. They are talking about a sorting algorithm that is used to order a list of items. In this guide, we\u2019re going to talk about&hellip;","protected":false},"author":240,"featured_media":19292,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17289],"tags":[],"class_list":{"0":"post-19291","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-java"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Java","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Java Bubble Sort: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Bubble Sort: A Guide\" \/>\n<meta property=\"og:description\" content=\"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-10T22:52:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:53:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\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:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Java Bubble Sort: A Guide\",\"datePublished\":\"2020-07-10T22:52:20+00:00\",\"dateModified\":\"2023-12-01T11:53:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/\"},\"wordCount\":1208,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/\",\"name\":\"Java Bubble Sort: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg\",\"datePublished\":\"2020-07-10T22:52:20+00:00\",\"dateModified\":\"2023-12-01T11:53:47+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/07\\\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java-bubble-sort\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Java Bubble Sort: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java Bubble Sort: A Guide | Career Karma","description":"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.","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:\/\/careerkarma.com\/blog\/java-bubble-sort\/","og_locale":"en_US","og_type":"article","og_title":"Java Bubble Sort: A Guide","og_description":"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.","og_url":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-10T22:52:20+00:00","article_modified_time":"2023-12-01T11:53:47+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Java Bubble Sort: A Guide","datePublished":"2020-07-10T22:52:20+00:00","dateModified":"2023-12-01T11:53:47+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/"},"wordCount":1208,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/","url":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/","name":"Java Bubble Sort: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg","datePublished":"2020-07-10T22:52:20+00:00","dateModified":"2023-12-01T11:53:47+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"A Java bubble sort compares adjacent items in a list and swaps them if they are not in order. On Career Karma, learn how to implement a bubble sort in Java.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/java-bubble-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/07\/maarten-van-den-heuvel-8EzNkvLQosk-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/java-bubble-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/careerkarma.com\/blog\/java\/"},{"@type":"ListItem","position":3,"name":"Java Bubble Sort: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=19291"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/19291\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/19292"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=19291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=19291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=19291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}