0% found this document useful (0 votes)
4 views3 pages

Java_String_Manipulation_Study_Guide_Preview

The Java String Manipulation Study Guide covers two key topics: reversing a string and checking if a string is a palindrome. It provides code examples for both tasks, highlighting their importance in interviews as tests of basic string and loop understanding. The guide encourages personal notes for further learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java_String_Manipulation_Study_Guide_Preview

The Java String Manipulation Study Guide covers two key topics: reversing a string and checking if a string is a palindrome. It provides code examples for both tasks, highlighting their importance in interviews as tests of basic string and loop understanding. The guide encourages personal notes for further learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java String Manipulation Study Guide

Table of Contents
1. Reverse a String

2. Check if Palindrome
Java String Manipulation Study Guide

1. Reverse a String

Description: Reverse a given string without using built-in reverse methods.

Interview Insight: Often used to test basic understanding of strings and loops.
public class ReverseString {
public static String reverse(String s) {
StringBuilder sb = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i--) {
sb.append(s.charAt(i));
}
return sb.toString();
}

public static void main(String[] args) {


System.out.println(reverse("hello")); // "olleh"
}
}

Your Notes: ____________________________

____________________________
Java String Manipulation Study Guide

2. Check if Palindrome

Description: Check if a string is a palindrome by comparing characters from both ends.

Interview Insight: Common warm-up interview question for string logic.


public class PalindromeCheck {
public static boolean isPalindrome(String s) {
int left = 0, right = s.length() - 1;
while (left < right) {
if (s.charAt(left++) != s.charAt(right--)) return false;
}
return true;
}

public static void main(String[] args) {


System.out.println(isPalindrome("madam")); // true
}
}

Your Notes: ____________________________

____________________________

You might also like