zuai-logo

Difference between substring() and charAt()?

substring(): Returns a substring. charAt(): Returns a single character.

Flip to see [answer/question]
Flip to see [answer/question]

All Flashcards

Difference between substring() and charAt()?

substring(): Returns a substring. charAt(): Returns a single character.

Difference between equals() and == for strings?

equals(): Compares content. ==: Compares references.

Difference between indexOf() and lastIndexOf()?

indexOf(): First occurrence. lastIndexOf(): Last occurrence.

Difference between toLowerCase() and toUpperCase()?

toLowerCase(): Converts to lowercase. toUpperCase(): Converts to uppercase.

Difference between replace() and replaceAll()?

replace(): Replaces first occurrence. replaceAll(): Replaces all occurrences (uses regex).

Difference between using a for loop and a while loop for string iteration?

for: Typically used when the number of iterations is known. while: Used when the number of iterations is unknown.

Difference between using StringBuilder and String for string manipulation?

String: Immutable, creates new objects. StringBuilder: Mutable, modifies the existing object.

Difference between using contains() and manually checking for a substring?

contains(): Built-in method, simpler. Manual: More control, potentially more efficient for specific cases.

Difference between using split() with a regular expression and a simple delimiter?

Regex: More flexible, handles complex patterns. Simple: Faster for basic delimiters.

Difference between using trim() and manually removing whitespace?

trim(): Removes leading and trailing whitespace. Manual: More control over which whitespace to remove.

Why use loops with strings?

To iterate through characters and substrings.

Explain string indexing.

Accessing characters by their position in the string.

What is the core idea of string reversal?

Building a new string by prepending characters.

How does a 'sliding window' work?

It extracts all substrings of a given length by moving one character at a time.

Why is equals() preferred over == for strings?

equals() compares content; == compares references.

Why is tracing important?

Helps visualize the process and catch errors early.

What is the importance of boundary conditions?

Ensuring algorithms work correctly at the start and end of strings.

What is the role of immutability in string manipulation?

Requires creating new strings for modifications.

Why is string searching important?

Fundamental in text processing and pattern recognition.

What is the time complexity of basic string operations?

Varies, but often O(n) for operations like searching or reversal.

How is string reversal used?

Palindrome checking, data encryption, and reversing words in a sentence.

How is substring checking used?

Text searching, content filtering, and code analysis.

How are string methods used in data validation?

Checking format, length, and allowed characters.

How are string algorithms used in bioinformatics?

Sequence alignment, gene finding, and protein analysis.

How are string algorithms used in search engines?

Indexing, query processing, and ranking results.

How is string manipulation used in web development?

Form validation, URL parsing, and dynamic content generation.

How is string processing used in natural language processing (NLP)?

Tokenization, stemming, and sentiment analysis.

How are string algorithms used in cybersecurity?

Password hashing, intrusion detection, and malware analysis.

How is string manipulation used in data science?

Data cleaning, feature extraction, and text mining.

How are string functions used in file processing?

Parsing file names, extracting data from text files, and manipulating file paths.