Can I remove a specific element from array by mentioning index value?
For example can I remove the character d by giving index value 1?
<
Using String class:
char[] words = { 'c', 'd', 'f', 'h', 'j' };
String str = new String(words);
words = (str.substring(0, Math.min(1, words.length)) + str.substring(Math.min(1 + 1, words.length))).toCharArray();
Running in jshell:
jshell> char[] words = { 'c', 'd', 'f', 'h', 'j' };
words ==> char[5] { 'c', 'd', 'f', 'h', 'j' }
jshell> String str = new String(words);
str ==> "cdfhj"
jshell> words = (str.substring(0, Math.min(1, words.length)) + str.substring(Math.min(1 + 1, words.length))).toCharArray();
words ==> char[4] { 'c', 'f', 'h', 'j' }
jshell>