- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract the last n characters from a string using Java?
To extract last n characters, simply print (length-n)th character to nth character using the charAt() method.
Example
public class ExtractingCharactersFromStrings { public static void main(String args[]) { String str = "Hi welcome to tutorialspoint"; int n = 5; int initial = str.length()-5; for(int i=initial; i<str.length(); i++) { System.out.println(str.charAt(i)); } } }
Output
p o i n t
- Related Articles
- How to extract the first n characters from a string using Java?
- How to extract initial, last, or middle characters from a string in R?
- How to extract the last 4 characters from NSString?
- How to extract characters from a string in R?
- How to extract certain substring from a string using Java?
- How to get last 2 characters from string in C# using Regex?
- How to extract first two characters from a string in R?
- How to get last 4 characters from string in\nC#?
- How to extract an HTML tag from a String using regex in Java?
- How to extract numbers from a string using Python?
- How to extract multiple integers from a String in Java?
- How to extract each (English) word from a string using regular expression in Java?
- Extract only characters from given string in Python
- How to extract numbers from a string using regular expressions?
- Java Program to Extract a Single Quote Enclosed String from a Larger String using Regex

Advertisements