You can use String#split:

String s = "14.015_AUDI";
String[] parts = s.split("_"); //returns an array with the 2 parts
String firstPart = parts[0]; //14.015

You should add error checking (that the size of the array is as expected for example)

Answer from assylias on Stack Overflow
🌐
AlgoCademy
algocademy.com › link
String Slicing in Java | AlgoCademy
This is particularly useful in scenarios where you need to manipulate or analyze specific parts of a string, such as parsing data, formatting output, or handling user input. The substring() method in Java is used to slice a string. It takes two parameters: startIndex and endIndex.
🌐
Baeldung
baeldung.com › home › java › java string › java equivalent to python’s easy string slicing
Java Equivalent to Python’s Easy String Slicing | Baeldung
March 25, 2025 - However, StringBuilder is more efficient because string concatenation inside a loop creates multiple immutable string objects, leading to performance overhead. Python allows slicing with a negative step, which extracts elements in reverse order within a specified range. This is useful for selecting characters in reverse or skipping elements while moving backward. ... Java does not have built-in support for negative step slicing, so we’ll manually iterate in the required order:
🌐
GeeksforGeeks
geeksforgeeks.org › java › substring-in-java
Java String substring() Method - GeeksforGeeks
April 11, 2025 - StringIndexOutOfBoundsException: This exception will happen when the index value is in cases such as negative beginIndex or an endIndex is greater than the length of the string or beginIndex is greater than the endIndex. Note: If we pass the start index and endIndex with the same value so it will return an empty substring (""). Example 1: Java program to extract a substring using substring(int beginIndex).
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
July 21, 2026 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string.
🌐
Pass4sure
pass4sure.com › blog › mastering-string-splitting-in-java-extracting-the-final-element-with-precision-and-performance
Mastering String Splitting in Java: Extracting the Final Element with Precision and Performance – IT Exams Training – Pass4Sure
String splitting is a basic string manipulation technique where a single string is divided into multiple substrings based on a delimiter. In Java, this is handled by the built-in split() method which returns an array of substrings.
🌐
Java2s
java2s.com › example › java-utility-method › string-slice-index-0.html
Java Utililty Methods String Slice
List of utility methods to do String Slice · HOME · Java · S · String Slice ·
🌐
Coding Champ
coding-champ.com › tutorials › java › string-slicing
Java - String Slicing
String slicing allows you to extract a portion of a string. Slicing of a string can be done via specifying starting index and optionally length.
🌐
Codecademy
codecademy.com › docs › java › strings › .substring()
Java | Strings | .substring() | Codecademy
April 28, 2025 - The .substring() method in Java returns a portion of a string from a specified starting index to an (optional) ending index.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-substring-method-example
Java String substring() Method with examples
It throws IndexOutOfBoundsException If the beginIndex is less than zero OR beginIndex > endIndex OR endIndex is greater than the length of String. Now that we understand the basics of substring() method, let’s take few examples to understand the usage of this method. Before we start to see some interesting substring method examples, let’s start with a simple example that demonstrates the usage of this method. public class JavaExample{ public static void main(String args[]) { String str= new String("WelcomeHome!"); System.out.print("Substring starting from index 7: "); System.out.println(str.substring(7)); System.out.print("Substring from beginIndex 3 till endIndex 7: "); System.out.println(str.substring(3, 7)); } }
🌐
Reddit
reddit.com › r/learnprogramming › how to correctly use the substring method? (java)
r/learnprogramming on Reddit: How to correctly use the substring method? (Java)
February 2, 2013 -

Hey guys, I've been working on this Java homework for my class and this whole section about string manipulation is confusing me.

The homework asks to add statements that use the substring method to get the first half and second half of phrase.

I'm assuming that means using the substring method, but I always get errors trying to compile what I put in. So here's the code. I'm not exactly sure how to use the substring method in the way they ask, and my book doesn't really go over it well. Should I be creating another variable or just use what I have?

🌐
Quora
quora.com › How-do-you-use-substring-and-lastIndexOf-in-Java
How to use substring and lastIndexOf in Java - Quora
Answer: The substring() method extracts characters, between two indices (positions), from a string, and returns the substring. The substring() method extracts characters from start to end (exclusive). The substring() method does not change the original string. The lastIndexOf() method returns th...
🌐
CodeGym
codegym.cc › java blog › strings in java › substring in java
Java String substring()
July 23, 2024 - Java Substring in general is a contiguous sequence of characters inside the String. It could be a part of the String or the whole String as well. What is substring in Java? This language has a substring() method, or rather two methods, thanks ...
🌐
Baeldung
baeldung.com › home › java › java string › how to truncate a string in java
How to Truncate a String in Java | Baeldung
January 8, 2024 - In this tutorial, we’ll learn multiple ways to truncate a String to a desired number of characters in Java.
🌐
IONOS
ionos.com › digital guide › websites › web development › java substrings
How to use the Java substring method - IONOS
January 6, 2025 - There are two different ways to use it, either sep­a­rat­ing the string from an index to the end or with a pre-defined beginning and ending index for the substring. In Java, char­ac­ters, digits and special char­ac­ters can be combined into a Java string.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › String.html
String (Java SE 17 & JDK 17)
April 21, 2026 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.