java remove character from string

java remove character from string

Java String class substring() method returns a substring of string.

Remove the last character of String in java

refer t‮:o‬lautturi.com
/**
 * @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);
	}
}

Remove the n-th character of String in java

/**
 * @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!
Created Time:2017-09-30 20:12:17  Author:lautturi