Check for duplicate characters in a String : Java

/**
* Checks if a String has a duplicate char.
* http://www.victorbyte.net/
* Returns boolean value
*/
public static boolean hasDuplicateChar(String str)
{

for (int index = 0, loop = 1; loop < str.length(); loop++)
{
if (str.charAt(index) == str.charAt(loop))
return true;
if (loop == str.length() - 1)
loop = ++index;
}

return false;
}
This entry was posted in internet. Bookmark the permalink.

One Response to Check for duplicate characters in a String : Java

  1. Anonymous says:

    very nice, every other solution i see is much more complicated

Leave a Reply

Your email address will not be published. Required fields are marked *