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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:06:34+00:00 2026-06-02T09:06:34+00:00

i have an ArrayList with elements for example: [a,b,c,d,e,f,g,h]; and need to take elements

  • 0

i have an ArrayList with elements for example:

[a,b,c,d,e,f,g,h];

and need to take elements [a,b,c] also it should be an ArrayList and remove them from first List and again i take some elements from first list after i take i remove them.

So what is the best way (considering a time) to do this job ?
I mean i should iterate over elements or should convert to array and than work with it ?

maybe there are some fast way to do this ?

Thanks.

  • 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-02T09:06:36+00:00Added an answer on June 2, 2026 at 9:06 am

    Create a new list using subList() to get a view into the first, then use clear() on the subList. Example:

    subList = originalList.subList(0, 3);
    newList = new ArrayList(subList);
    subList.clear();
    

    This is much more efficient than iterating over the original list removing one element at a time since removing an element from an ArrayList involves shifting all the elements. Using a subList does the shift just once.

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

Sidebar

Related Questions

I have this arrayList: ArrayList<ArrayList<Integer>> temporary = new ArrayList<ArrayList<Integer>>(); Some how I need to
for example I have an ArrayList with 2 elements, but Eclipse Java debugger shows
I have list of String. List<String> elements= new ArrayList<String>(); when I wanna add new
I have written this code to join ArrayList elements: Can it be optimized more?
I have 4 arraylist in jsp and I want to get elements of lists
i have an arraylist, and for some reasons it overwrites all previous values and
I have static ArrayList<Batch> . i want to remove which object contain productcode This
I have `a string example = this site holds all the examples from The
For example, say I have an ArrayList that could contain the following values: x
I have a list of embedded entities: @Embedded private List<EmbeddedEntity> embedded = new ArrayList<EmbeddedEntity>();

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.