0% found this document useful (0 votes)
5 views39 pages

Convert Int Input To String (Lec Resource)

The document outlines a checklist for understanding strings in Java, covering topics such as string immutability, the CharSequence interface, and various built-in functions. It includes questions and exercises related to string manipulation, such as counting vowels, generating substrings, and reversing words. Additionally, it discusses performance comparisons between strings and StringBuilder, as well as common string-related problems and their solutions.

Uploaded by

Pranav Teja
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)
5 views39 pages

Convert Int Input To String (Lec Resource)

The document outlines a checklist for understanding strings in Java, covering topics such as string immutability, the CharSequence interface, and various built-in functions. It includes questions and exercises related to string manipulation, such as counting vowels, generating substrings, and reversing words. Additionally, it discusses performance comparisons between strings and StringBuilder, as well as common string-related problems and their solutions.

Uploaded by

Pranav Teja
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/ 39

Strings

Today’s checklist
1. Basics of Strings
2. String immutability in java
3. CharSequence Interface
4. Built-in stringBuilder functions
5. Problems based on strings
6. Sorting a string using in-built functions
7. Integer.parseInt function
What are strings and Why are
they used?
Declaration of Strings and taking
Input
charAt() and length()
Ques:
Q1 : Input a string and count all the vowels in the given
string.
indexOf() and compareTo()
indexOf() and compareTo()
contains() and startsWith()
toLowerCase() and concat()
substring(i) & substring(i,j)
Ques:
Q2 : Input a string and print all the substrings of that string.
"abod" ;
string s
:
String + int / char / String
sout(“abc”+10+20)
Ques:
Q3 : Take integer input and convert it into a String.
Ques:
Q4 : Return the total number of digits in a number without
using any loop.
Hint : Try using inbuilt Integer.toString() function.

n = 1256 -
Gans
""
n +
;
string s =

sout (s Length (1)


. :
Interning and new keyword

I
-
Strings =
"Raghar" ; "Raghar"
S
"Madhav" ;
S =
"Madhav"
"Madhav" ;
string t + M
=

String =
"Raghar"
a - "Raghar"
So save space
string a =
new String ("Raghow") ;
String immutability in java
Ques:
Q5 : Input a string and Update all the even positions in the
string to character ‘a’. Consider 0-based indexing.
Performance of Strings
equals() vs ==
equals() vs ==
StringBuilder
StringBuilder - Input
setCharAt()
Ques:
Q6 : Input a string and toggle all the characters of it.
(Replace small case with capital case & vice versa)
append()
insert() and deleteCharAt()
reverse()
Ques:
Q7 : Reverse each word in a given sentence.
I Il

(Ex : i am raghav garg -> i ma vahgar grag)

123456789101112131415
reverse (sb ,
i, j-1) ;
0

Sb = I ma valgar garg
i j
Ques:
Q7 : Reverse each word in a given sentence.
(Ex : i am raghav garg -> i ma vahgar grag)
Sorting a string 11

J "Waghav
Immutable ↓
string -

X E
aaghou
Ques:
Q8 : Given two strings s and t, return true if t is an anagram
of s, and false otherwise.

[Leetcode 242]
Ques:
Q9 : Given n strings consisting of lowercase English
alphabets. Print the character that is occurring most
number of times.
Ques:
Q10 : Given two strings s and t, determine if they are
isomorphic.

[Leetcode 205]
Ques:
Q10 : Given two strings s and t, determine if they are
isomorphic.

[Leetcode 205]
Ques:
Q11 : Given n string consisting of digits from 0 to 9. Return
the string which has maximum value.
Ques:
Q12 : Compress a given string.

[Leetcode 443]
THANK YOU

You might also like