Delete string from position m to n
Example:
Input: str="Hello World"
Output: Hlo World
Approach
Java
public class StrDeleteMTON {public static void main(String[] args) {String str = "Hello World";String newstr = str.substring(0, 1) + str.substring(1 + 2);System.out.println(newstr);}}
Approach: using string buffer
Java
public class StrDeleteMTON {public static void main(String[] args) {String str = "Hello World";StringBuffer sb = new StringBuffer(str);sb = sb.delete(1, 2);System.out.println(sb.toString());}}
No comments:
Post a Comment