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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:54:32+00:00 2026-05-28T17:54:32+00:00

I’m trying to create a list of objects and then a sublist and then

  • 0

I’m trying to create a list of objects and then a sublist and then delete all the elements in the sublist and then once again display the main list. However when I try to remove elements from a sublist I get error at runtime indexoutofbounds and unknown source. How to fix that so that the app works?

import java.util.*;

class Eval{
    Eval(){         
    }   
}

public class Ch11Ex7 {
    public static void main(String[] args){ 

        Eval e1 = new Eval();
        Eval e2 = new Eval();
        Eval e3 = new Eval();
        Eval e4 = new Eval();
        Eval e5 = new Eval();

        Eval[] eva = {e1, e2, e3, e4, e5};

        //ArrayList<Eval> ev = new ArrayList<Eval>(Arrays.asList(eva));
        List ev = Arrays.asList(eva);
        List<Eval> sub = ev.subList(1, 3);  
        for(int i=0; i< ev.size() ; i++)
              System.out.println(ev.get(i));        
        System.out.println("Sublist");  
        for(int i=0; i< sub.size() ; i++)
              System.out.println(sub.get(i));   
        System.out.println("Remove element");
        sub.remove(2);
    }
}
  • 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-28T17:54:34+00:00Added an answer on May 28, 2026 at 5:54 pm

    Java Lists are zero indexed, so:

    List<Eval> sub = ev.subList(1, 3) // = {e2, e3} (subList is not inclusive on second index)
    

    And

    sub.remove(2); // Attempts to remove 3rd element from 2 element list
    

    So, reduce your indexes by one.

    import java.util.*;
    
    class Eval{
    Eval(){         
    }   
    }
    
    public class Ch11Ex7 {
    public static void main(String[] args){ 
    
        Eval e1 = new Eval();
        Eval e2 = new Eval();
        Eval e3 = new Eval();
        Eval e4 = new Eval();
        Eval e5 = new Eval();
    
        Eval[] eva = {e1, e2, e3, e4, e5};
    
        //ArrayList<Eval> ev = new ArrayList<Eval>(Arrays.asList(eva));
        List ev = Arrays.asList(eva);
        List<Eval> sub = ev.subList(0, 2); 
        sub = new ArrayList<Eval>(sub);
        for(int i=0; i< ev.size() ; i++)
              System.out.println(ev.get(i));        
        System.out.println("Sublist");  
        for(int i=0; i< sub.size() ; i++)
              System.out.println(sub.get(i));   
        System.out.println("Remove element");
        sub.remove(1);
    }
    

    }

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the

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.