Lets say that I have an array as followed :
String[] letter = {a, b, c, e, f, }
How can I trim this array in order to get rid the empty element?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no “empty” element in that array. The trailing comma makes no difference – your array still has 5 elements.
If you have a real problem in real code where some elements in an array are empty (and you’ll have to say what you mean by that – null value? Value referring to an empty string?) you can’t change the size of an existing array, but you can create a new array, e.g. with