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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:06:18+00:00 2026-05-18T05:06:18+00:00

So i am creating a class for MiniString which is just full of instance

  • 0

So i am creating a class for “MiniString” which is just full of instance methods for the object MiniString, every MiniString has an instance variable that is a char[]. When testing my methods, I can’t find where I am going wrong with my substring() method. There are two substring methods where one takes a parameter of int and the other takes two int parameters. I keep getting the error on the one int parameter method. The substring method is supposed to return a new MiniString formed of the characters between the position in the target Ministring specified by the int parameter, and the end of the target MiniString. The error I keep getting in my JUnit Tester is the following:

java.lang.ArrayOutofBoundsException:22
at MiniString.substring(MiniString.java:141)
at MiniString.substring(MiniString.java:159)

Here are my constructors for the object MiniString:

private char[] miniscule;

 MiniString(char[] array){
  int i = 0;
  miniscule = new char[array.length];
  while (i < array.length){
   miniscule[i] = array[i];
   i++;
  }
 }
 MiniString(String string){
  int i = 0;
  miniscule = new char[string.length()];
  while (i < string.length()){
   this.miniscule[i] = string.charAt(i);
   i++;
  }
 }

and here is the code for the two substring() methods:

public MiniString substring(int start, int end){
  int i = start; 
  if (end > start){
   char[] temp = new char[end - start];
   MiniString range = new MiniString(temp);
   while (i < end){
    range.miniscule[i] = this.miniscule[i];
    i++;
   }
   return range;
  }
  else{
   char[] temp = new char[1];
   MiniString range = new MiniString(temp);
   range.miniscule[0] = 0;
   return range;
  }
 }
 public MiniString substring(int position){
  int start = position;
  int end = this.miniscule.length;
  char[] temp = new char[end - start];
  MiniString output = new MiniString(temp);

  output = substring(start, end);
  return output;
 }

Thanks for your help!

  • 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-18T05:06:18+00:00Added an answer on May 18, 2026 at 5:06 am

    In your first substring method, the line

    range.miniscule[i] = this.miniscule[i];
    

    is the most likely suspect. I expect you really want

    range.miniscule[i - start] = this.miniscule[i];
    

    String has substring methods that do approximately what you’re doing here, but I presume you’re doing this to learn, rather than reinventing string handling for a production use.

    If you’re using Java 6, you might also want to look at the Arrays.copyOfRange(T[] ts, int i, int i1) method, which does most of the work you’re doing in your substring methods.

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

Sidebar

Related Questions

When creating a class that has internal private methods, usually to reduce code duplication,
I'm creating a class (say, C) that associates data (say, D) with an object
I'm creating a class that will have one public method, which returns a value
Just assume I have some class Foo, that has two dependencies: an ISerializer<T> and
I am creating a class that determines which of number of registered WCF client
If I'm creating a class, and I will load an object of that class
I'm creating a class. What's the best practice for naming properties/methods when your preferred
I'm creating a class that derives from List... public class MyList : List<MyListItem> {}
I am creating a class that implements java.util.List . My class is using E
I'm developing a desktop application. For that I'm creating class libraries. At the development

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.