[Java] How to use substring to cut out a part of a character string

When specifying the start position

String.substring(int beginIndex)
public class Main {
 
    public static void main(String[] args) {
        String sports = "soccer,baseball,basketball";
 
        System.out.println(sports.substring(7));
    }
 
}

Execution result

baseball,basketball

When specifying the start and end positions

String.substring(int beginIndex, int endIndex)
public class Main {
 
    public static void main(String[] args) {
        String sports = "soccer,baseball,basketball";
 
        System.out.println(sports.substring(7, 15));
    }
 
}

Execution result

baseball

reference

Java (tm) Platform, Standard Edition 8 API Specifications

Recommended Posts

[Java] How to use substring to cut out a part of a character string
[Java] How to use substring to cut out a character string
[Java] How to cut out a character string character by character
[Java] Cut out a part of the character string with Matcher and regular expression
[Java] How to erase a specific character from a character string
[Java] How to convert a character string from String type to byte type
[Java] [Maven3] Summary of how to use Maven3
How to check for the contents of a java fixed-length string
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
[Java] How to convert one element of a String type array to an Int type
[Java] How to easily get the longest character string of ArrayList using stream
[Java] How to use compareTo method of Date class
Summary of Java communication API (1) How to use Socket
Summary of Java communication API (3) How to use SocketChannel
Summary of Java communication API (2) How to use HttpUrlConnection
[Java] How to use Map
[Java] How to use Map
How to use java Optional
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
Cut out a Ruby string
<Java> Quiz to batch convert file names separated by a specific character string with a part of the file name
How to use trained model of tensorflow2.0 with Kotlin / Java
How to create a placeholder part to use in the IN clause
How to store a string from ArrayList to String in Java (Personal)
[Introduction to Java] Handling of character strings (String class, StringBuilder class)
A story about misunderstanding how to use java scanner (memo)
How to use Java HttpClient (Get)
How to make a Java container
How to use Java HttpClient (Post)
How to use setDefaultCloseOperation () of JFrame
[Processing × Java] How to use variables
[Java] How to create a folder
[Java] How to use LinkedHashMap class
[JavaFX] [Java8] How to use GridPane
How to use class methods [Java]
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to make a Java array
How to use Java lambda expressions
[Java] How to use Math class
How to use Java enum type
[Java] Divide a character string by a specified character
How to make a Java calendar Summary
A memorandum on how to use Eclipse
[Java] How to use the File class
[Java] How to use the hasNext function
[java] Summary of how to handle char
How to use submit method (Java Silver)
[Java] How to use the HashMap class
[Easy-to-understand explanation! ] How to use Java instance
[Introduction to Java] How to write a Java program
[Java] How to use the toString () method
Studying how to use the constructor (java)