
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to remove a character at a specified position
To remove a character at a specified position, use the following logic −
Let’s say the following is our string.
String str = "The Haunting of Hill House!";
We want to remove a character at position 7. For that, use the below logic.
// removing character at position 7 int pos = 7; String res = str.substring(0, pos) + str.substring(pos + 1);
The following is the complete example with output.
Example
public class Demo { public static void main(String[] args) { String str = "The Haunting of Hill House!"; System.out.println("String: "+str); // removing character at position 7 int pos = 7; String res = str.substring(0, pos) + str.substring(pos + 1); System.out.println("String after removing a character: "+res); } }
Output
String: The Haunting of Hill House! String after removing a character: The Hauting of Hill House!
- Related Questions & Answers
- Java Program to get a character located at the String's specified index
- The listIterator() method AbstractList class in Java at a specified position
- Insert the specified element at the specified position in Java CopyOnWriteArrayList
- The listIterator() method of CopyOnWriteArrayList in Java starting at a specified position
- Java Program to Replace a Character at a Specific Index
- Insert a character at nth position in string in JavaScript
- Insert a specified element in a specified position in JavaScript?
- Remove a character from a Java StringBuffer object
- Left pad a String with a specified character in Java
- Search for a character from a given position in Java
- In MySQL, how can we insert a substring at the specified position in a string?
- Java Program to Add Element at First and Last Position of a Linked list
- Insert a specified HTML text into a specified position in the JavaScript document?
- C# program to remove n-th character from a string
- Set the bit at a specific position in the BitArray to the specified value in C#?
Advertisements