Try:- Quick way to check if all the characters of a string are same

 // Java program to find whether the String

// has all same characters or not.

import java.io.*;


public class GFG{


static boolean allCharactersSame(String s)

{

int n = s.length();

for (int i = 1; i < n; i++)

if (s.charAt(i) != s.charAt(0))

return false;

return true;

}


// Driver code

static public void main (String[] args){

String s = "aaa";

if (allCharactersSame(s))

System.out.println("Yes");

else

System.out.println("No");

}

}


// This Code is contributed by vt_m.


Comments

Popular posts from this blog

Git and Github

bubble short Q1

Java Program to Check Whether the String Consists of Special Characters