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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:52:26+00:00 2026-06-04T05:52:26+00:00

I have an ArrayList named play_viewCount : I am sorting this ArrryList and storing

  • 0

I have an ArrayList named play_viewCount: I am sorting this ArrryList and storing it in a new ArrayList.

Now I have sorted ArrayList: but what I want is before sorting what was the position of new items in ArrayList?

ArrayList<String> sort_play_viewCount = play_ViewCount; // here play_viewCount is ArrayList
ArrayList<Integer> position_array = new ArrayList<Integer>(); 
System.out.println("......................................... Play Count :"+sort_play_viewCount);
Collections.sort(sort_play_viewCount);
System.out.println(".........................................sort Play Count :"+sort_play_viewCount);

for(int j = 0; j<sort_play_viewCount.size(); j++){
    for(int k = 0; k<sort_play_viewCount.size(); k++){
        if(play_ViewCount.contains(sort_play_viewCount.get(j))){
            position_array.add(k);
        }
    }
}

System.out.println(" .................Position Array: "+position_array);

Does anyone know how to get the positions of the new items before sorting?

  • 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-04T05:52:29+00:00Added an answer on June 4, 2026 at 5:52 am

    Try doing a little differently:

    ArrayList<Integer> position_array = new ArrayList<Integer>(); 
    
    position_array.addAll(play_viewCount);
    Collections.sort(position_array);
    

    Now position_array is sorted, and to get the previous positions you can just call play_viewCount.indexOf(value);

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

Sidebar

Related Questions

I have arraylist myorderdata . I want to retrieve this arraylist to one String
Say I have List<SomeObject> objList = new ArrayList<SomeObject>(); If SomeObject contains a field named
Before I have hardcoded the positions of Image view and name but now I
I have an ArrayList<String> named listout, I want to convert it to an ArrayList<SelectItem>
I have problem with this. I have one arrayList, and I want to copy
I have wriiten a method like this public ArrayList<T> GetDoctorDetail(String name) { if (name!=null
I have an ArrayList that I want to use to hold RaceCar objects that
I have a class named ExampleHandler extends from DefaultHandler . This class reads data
I have an arraylist with a custom object type named StartsideElement. <c:forEach items=#{startsideClient.brukerelementer} var=element
I have a class named Person .This class represents (as the name says) a

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.