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 8716525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:05:54+00:00 2026-06-13T06:05:54+00:00

Suppose you have an arraylist of 10 indexes including either the numbers 1, 2,

  • 0

Suppose you have an arraylist of 10 indexes including either the numbers 1, 2, or 3 only. I am trying to get these to print without repeating the same number consecutively if possible.

For example, arraylist includes the numbers {1,1,1,2,1,2,2,3,1,2}
I would like it to print as: {1,2,3,1,2,1,2,1,2,1}

Sorry if this can be done much simpler than what I am trying to do. I am still pretty new to programming.

    int j;
    int k;
    for (j=0; j<p.size()-1;j++)
    {
        for(k =1; k<p.size()-1;k++)
        {      
            if(p.get(k)==p.get(j))
            {
    //       Person temp = p.get(j);
    //       p.remove(j);
    //       p.add(temp);
            }        
        }
    }
  • 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-13T06:05:55+00:00Added an answer on June 13, 2026 at 6:05 am

    Not just that.. Try this:

    for (int i = 0; i < list.size() - 1; i++) {
        if (!list.get(i+1).equals(list.get(i)) {
            System.out.print (list.get(i));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an ArrayList<Fruit> I would like to get all elements from this
Suppose I have ArrayList with following contents public void add() { obj.add(1); obj.add(123456789); obj.add(1.222);
Suppose i have a List<Integer> l = new ArrayList<Integer>(); and would like to have
I have an arrayList of object Player. Player has field id, and score. suppose
suppose I have arraylist of integers...is there a way that I can generate a
so suppose i have ArrayList<E> X = new ArrayList<E>(); and I pass X into
suppose I have an arraylist of the form ArrayList<ArrayList<E>> ... what would be the
I have object arraylist,I have to apply search operation on name basis.suppose there are
Suppose I have a class MyClass which can be instantiated either with String or
How can I remove specific object from ArrayList? Suppose I have a class as

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.