可以说你有这样一个数组:String[] theWords = {"hello", "good bye", "tomorrow"}
。我想删除/忽略数组中具有字母'e'的所有字符串。我会怎么做呢?我的想法是:Java:由于字符而从阵列中删除项目
for (int arrPos = 0; arrPos < theWords.length; arrPos++) { //Go through the array
for (int charPos = 0; charPos < theWords[arrPos].length(); charPos++) { //Go through the strings in the array
if (!((theWords[arrPos].charAt(charPos) == 'e')) { //Finds 'e' in the strings
//Put the words that don't have any 'e' into a new array;
//This is where I'm stuck
}
}
}
我不知道我的逻辑是否有效,如果我甚至在正确的轨道上。任何回应都会有帮助。非常感谢。
考查:使用1)的ArrayList,不是数组,以及2)在字符串'包含(...)'方法。 –
为什么不使用'ArrayList'。如果你的任务是使用数组,那么你应该使用'contains'来检查'character'或'word' –
我还没有在类中学习ArrayList,而且数组对我来说还是比较新的。 –