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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:10:34+00:00 2026-05-31T04:10:34+00:00

I have two arraylists and the second one is a subset of the first.

  • 0

I have two arraylists and the second one is a subset of the first.
I want to know the initial and final position in the first arraylist of elements in the subset (in my example the position in arrayList of: uno, due, tre)

How to modify this code?

import java.util.ArrayList;

public class ConfrontaArrayList {
public static void main(String[] args)
{
    ArrayList<String> arrayList = new ArrayList<String>();
    ArrayList<String> subSetArrayList = new ArrayList<String>();

    arrayList.add("inizio");
    arrayList.add("stringa");
    arrayList.add("uno");
    arrayList.add("due");
    arrayList.add("tre");
    arrayList.add("fine");
    arrayList.add("stringa");

    subSetArrayList.add("uno");
    subSetArrayList.add("due");
    subSetArrayList.add("tre");

    System.out.print("Elementi di arrayList: ");
    for (String stringa : arrayList) System.out.print(stringa + " ");
    System.out.print("\nElementi di subSetArrayList: ");
    for (String stringa : subSetArrayList) System.out.print(stringa + " ");
}
}  
  • 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-05-31T04:10:35+00:00Added an answer on May 31, 2026 at 4:10 am

    java.util.Collections.indexOfSubList() method will return the index of the sub list:

    int startIdx = Collections.indexOfSubList(arrayList, subSetArrayList);
    if (-1 != startIdx)
    {
        int endIdx = startIdx + subSetArrayList.size() - 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have two spreadsheets... when one gets modified in a certain way I want
I have two arraylists, and I would like to have a new arraylist with
I have two arraylists, one contains Strings and the other contains Classes that have
I have a problem with comparing two arraylist, my first arraylist looks like this:
I have two ArrayLists of different lengths. One contains ints, the other contains objects
Assuming I have two methods. One that creates an arraylist and returns it, the
I have two ArrayLists. ArrayList A contains: ['2009-05-18','2009-05-19','2009-05-21'] ArrayList B contains: ['2009-05-18','2009-05-18','2009-05-19','2009-05-19','2009-05-20','2009-05-21','2009-05-21','2009-05-22'] I have
There are two sub-problems. 1- Comparing two huge arraylists 2- Sorting elements of arraylist
I have used FrameLayout in which I have used two LinearLayouts. The second one

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.