Java String class substring() method returns a substring of string.
/**
* @author lautturi.com
* Java example: java remove character from string
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String str = "hello lautturi python world!";
// Remove the last character of String
String newStr = str.substring(0,str.length()-1);
System.out.println(newStr);
}
}
/**
* @author lautturi.com
* Java example: remove character from string
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String str = "hello lautturi python world!";
int pos = 5;
String newStr = str.substring(0,pos-1) + str.substring(pos,str.length());
System.out.println(newStr);
}
}
output:
hell lautturi python world!