I need to write a single generic method which can take both an array and a String reference. Inside such method, depending on the argument, I need to check for equality as well as do indexing. For array, the indexing is of course [] operator, but for String, it is charAt() method. Besides, I want to iterate over the argument, so for array I will be using length field and for String I will be using length() method. For equality, I need to use equals() method for array and == for chars in the String.
Is it something I'd better off write two separate overloaded methods, or it is worth the efforts to make it a generic method.
If in the latter case, how to do this?