You are calling str.substring(i, j-i)
which means substring(beginIndex, endIndex)
, not substring(beginIndex, lengthOfNewString)
.
One of assumption of this method is that endIndex
is greater or equal beginIndex
, if not length of new index will be negative and its value will be thrown in StringIndexOutOfBoundsException
.
Maybe you should change your method do something like str.substring(i, j)
?
Also if size
is length of your str
then
for (int i = 0; i <= size; i++)
should probably be
for (int i = 0; i < size; i++)
Related Posts:
- Error: Could not find or load main class in intelliJ IDE
- intellij idea – Error: java: invalid source release 1.9
- Java compile error: “reached end of file while parsing }”
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- Non-static variable cannot be referenced from a static context
- Lombok and Maven
- Else without if
- unused import statement for used ones in IntelliJ IDEA
- Error: JavaFX runtime components are missing, and are required to run this application with JDK 11
- How to fix “unsupported class file major version 60” in IntelliJ?
- intellij incorrectly saying no beans of type found for autowired repository
- JAVA_HOME should point to a JDK not a JRE
- IDEA: javac: source release 1.7 requires target release 1.7
- What does “error: ‘.class’ expected” mean and how do I fix it
- IntelliJ – Can’t start – “JAVA_HOME does not point to a valid JVM installation”
- Java error: void cannot be converted to String
- Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
- Fatal error compiling: tools.jar not found:
- Error: Module not specified (IntelliJ IDEA)
- Invalid signature file digest for Manifest main attributes exception while trying to run jar file
- Error: ‘)’ expected compiler error
- java attempting to assign weaker access privilege error
- What is the difference between run-time error and compiler error?
- “Cannot start compilation: the output path is not specified for module…”
- Class JavaLaunchHelper is implemented in two places
- IntelliJ IDEA “The selected directory is not a valid home for JDK”
- How to check if a String contains another String in a case insensitive manner in Java?
- Failed to write core dump. minidumps are not enabled by default on client version of windows
- How do I resolve ClassNotFoundException?
- Editor does not contain a main type in Eclipse [duplicate]
- How to replace � in a string
- “Missing return statement” within if / for / while
- How to convert byte array to string and vice versa?
- good example of Javadoc
- How do popBackStack() and replace() operations differ?
- Can’t find mysqladmin on Mac OSX 10.6.8
- What is an AssertionError? In which case should I throw it from my own code?
- How to write a Unit Test?
- Java Undefined Object
- Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
- How to convert an ArrayList containing Integers to primitive int array?
- Left Hand Side of an Assignment must be a Variable CharAt
- Compiling a java program into an executable
- Java Installation Not Completed / Unable to install Java
- Convert an integer to an array of characters : java
- How to compare dates in Java?
- Java integer-double division confusion
- How to set or change the default Java (JDK) version on macOS?
- How can I create an array of linked lists in java?
- What’s the difference between session.persist() and session.save() in Hibernate?
- This view is not constrained
- Enhanced FOR loops in C++
- How can I create an Array of ArrayLists?
- Create a List of primitive int?
- Compiling error: Return type for the method is missing
- Range of valid character for a base 64 encoding
- How to parse JSON boolean value?
- How to create an 2D ArrayList in java?
- java.lang.NumberFormatException: null i
- How do you #include files in java?
- How to use Java in Visual Studio 2017
- List of Arrays in Java
- Extending from two classes
- Web server failed to start. Port 8080 was already in use. Spring Boot microserviceWeb server failed to start. Port 8080 was already in use. Spring Boot microservice
- Could not resolve placeholder in string value
- All inclusive Charset to avoid “java.nio.charset.MalformedInputException: Input length = 1”?
- javac error: Class names are only accepted if annotation processing is explicitly requested
- JOptionPane YES NO OPTION
- Why it is mandatory to use “throws IOException”
- Terminating a Java Program
- How to add an image to a JPanel?
- How to create JSON Object using String?
- How to repaint a JPanel after have drawn on it?
- Why doesn’t RecyclerView have onItemClickListener()?
- Can a normal Class implement multiple interfaces?
- What kind of Java type is “[B”?
- Hibernate – Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
- Node cannot be resolved to a type
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Big Oh for (n log n)
- Invalid initial heap size. Could not create the Java virtual machine
- implicit super constructor object() is undefined. must explicitly invoke another constructor
- How to convert a String into an ArrayList?
- Making a deep copy of a LinkedList in java
- Difference between jar and war in Java
- Adding image to JFrame
- Java Fraction Calculator
- How to convert a date to milliseconds
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- How do I join two lists in Java?
- How to insert multiple tabs string in java?
- Java methods getting euclidean distance
- Setting background color for a JFrame
- Does java have “get line”?
- User Input not working with keyboard.nextLine() and String (Java)
- javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake during web service communicaiton
- Generate UML Class Diagram from Java Project
- how to convert .java file to a .class file
- Eclipse message saying List cannot be resolved to a type