
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if One String is a Rotation of Another in Java
To find weather a string is rotation of another, concat the first string to itself twice and find weather
Example
public class Sample { public static void main(String args[]){ String str1 = "gala"; String str2 = "alag"; String s3 = str1+str1; if(s3.contains(str2)) { System.out.println("str1 is rotation of str2"); } else { System.out.println("str1 is not rotation of str2"); } } }
Advertisements