Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8488227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:28:30+00:00 2026-06-10T21:28:30+00:00

I have been trying to implement Bubble Sort using simple integer array in java.

  • 0

I have been trying to implement Bubble Sort using simple integer array in java. However there seems to be some problem. Now i know that using ArrayList would be the best option and I would do that too. But why isnt it getting sorted with simple integer array.Here is the code

package sort;

public class BubbleSort {

    int array[]={1,5,3,32,54,6,87,5,1};
    int temp=0;
public void enter(){
    for(int i=0;i<array.length;i++){
        for(int j=0;j<(array.length-i);j++){
            if(array[j]>=array[j+1]){


                temp=array[j];
                array[j]=array[j+1];
                array[j+1]=temp;
                }

        }
    }
}
public void show(){

    for(int i:array){
    System.out.println(i);
    }
}
public static void main(String str[]){

    new BubbleSort().Enter();
    new BubbleSort().Show();
}
}

Its producing the same array as entered. Nothing is getting changed. The difference between a simple array and an ArrayList or Vector ,is just that they offer dynamic time expansion of array size.Is there anything more to it? I mean does simple array creates a different instance every time it is manipulated, just like Strings? It does seem to do so here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:28:32+00:00Added an answer on June 10, 2026 at 9:28 pm

    The problem is that you’re not assigning a name to the instantiation of your BubbleSort class.

    new BubbleSort().Enter();
    new BubbleSort().Show();
    

    Your code creates a new BubbleSort class, and then sorts it. And then it creates another new (and completely separate) BubbleSort class, and displays that one instead – and it hasn’t been sorted.

    You want to give a name to your variable, so you can sort it and then display it, like this:

    BubbleSort myBubbleSort = new BubbleSort();
    myBubbleSort.Enter();
    myBubbleSort.Show();
    

    As a side note (and as pointed out in SiB’s answer), you may also want to check out the Java Naming Conventions. Following these conventions makes your code more legible to other Java programmers, and includes things like using lowerCamelCase for method names, and UpperCamelCase for class names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been trying to implement SSO using SAML in Java. for quite some
I have been trying to implement hash-tables using uthash.h, following the (excellent) documentation I
i have been trying to implement a bottombar for my site, however the vision
Simply I have been trying to implement what BufferedStreamReader does in Java. I have
I have been trying to implement a factorial function using the actor model with
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I have been trying to implement pinch zoom/in-out for PhotoView (a UIImageView instance) using
I have been trying to implement the Authorize.NEt SIM Method using the information given
I have been trying to implement counting sort. It requests the user for the
I have been trying to implement various types of sort in a program am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.