//* Using stack
public static boolean isPalindrome(String string)
{
String rev="";
Stack stack = new Stack();
for(int i=0;i
5 Answers
//* Using stack
public static boolean isPalindrome(String string)
{
String rev="";
Stack stack = new Stack();
for(int i=0;i
//Reverse Words In a String
public static String reverseWords(String s)
{
String res="";
String[] string=s.split(" ");
for(int i=0;i=0;i--)
{
rev=rev+string.charAt(i);
}
return rev;
}
//*Counting duplicates
public static int countDuplicates(String str)
{
char[] charArray = str.toCharArray();
Map hash_map = new HashMap();
for(int i=0;i entry:hash_map.entrySet())
{
if(entry.getValue()>1)
{
count=count+1;
}
}
return count;
}
//Reverse Words in String
public static String reverseWords(String string){
String[] stAr=string.split(" ");
String result="";
for(int i=stAr.length-1;i>=0;i--)
{
result=result+" "+stAr[i];
}
return result.subString(1,result.length());
}
To comment on this, Sign In or Sign Up.
Would you like us to review something? Please describe the problem with this {0} and we will look into it.
Your feedback has been sent to the team and we'll look into it.
public static boolean isPalindrome(String string)
{
String reverse ="";
for(int i=string.length()-1;i>=0;i--)
{
reverse=reverse+string.charAt(i);
}
if(string.equalsIgnoreCase(reverse)
{
return true;
}
return false;
}