How to Get Substring Items Within Arraylist in Java? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Java, ArrayList is the pre-defined class of the Java collection framework, and it is part of java.util package. ArrayList can be used to add or remove an element dynamically in a Java program. It can be dynamically based on the elements added or removed from the ArrayList. In this article, we will be discussing how to get substring items within ArrayList in Java. Methods to get the substrings items within ArrayList Two methods are mostly used to implement to get the substrings items within ArrayList in the Java program. add(): It is a pre-defined method of the ArrayList that can be used to add the elements to the ArrayList.substring(startIndex, endIndex): It is also an in-built method, and it can be used to generate the substring with the specified starting index and ending index parameter of the method.Java Program to Get the Substrings Items within ArrayList Java // Java Program to Get Substrings from an ArrayList of Strings import java.util.ArrayList; public class GFGSubstringArrayList { // Main method public static void main(String[] args) { // Create the ArrayList of Strings named as mainList ArrayList<String> mainList = new ArrayList<>(); // Adding values to mainList mainList.add("Programming"); mainList.add("Java"); mainList.add("Spring"); mainList.add("SpringBoot"); // Define the startIndex and endIndex of the substring int startIndex = 3; int endIndex = 5; // Get substrings from the ArrayList ArrayList<String> substringList = getSubstrings(mainList, startIndex, endIndex); // Print the result System.out.println("Original ArrayList: " + mainList); System.out.println("Substrings ArrayList: " + substringList); } // Method to get substrings from an ArrayList of Strings private static ArrayList<String> getSubstrings(ArrayList<String> list, int startIndex, int endIndex) { ArrayList<String> substringList = new ArrayList<>(); for (String str : list) { // Check if the string is long enough for the specified indices if (str.length() >= endIndex) { substringList.add(str.substring(startIndex, endIndex)); } else { // Handle the case where the string is shorter than the specified indices substringList.add("No SubString"); } } return substringList; } } OutputOriginal ArrayList: [Programming, Java, Spring, SpringBoot] Substrings ArrayList: [gr, No SubString, in, in] Explanation:In the above program, we are getting the substring item within the ArrayList. We have created the ArrayList and added the elements into the ArrayList.After that defined one more method to convert the substrings with the specified starting index and ending of the parameters of the substring in the program. Comment More info K kadambalamatclo Follow Improve Article Tags : Java Java Programs Java-ArrayList substring Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like