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

String Manipulation Techniques for Interviews

The document discusses string manipulation, emphasizing its importance in interviews and explaining concepts such as immutability, copy constructors, and string methods like .next() and .split(). It also covers loops, function definitions, function overloading, and recursion, highlighting their roles in programming. Additionally, it touches on mutability and various string operations like concatenation and substring extraction.

Uploaded by

faberneil60
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)
3 views3 pages

String Manipulation Techniques for Interviews

The document discusses string manipulation, emphasizing its importance in interviews and explaining concepts such as immutability, copy constructors, and string methods like .next() and .split(). It also covers loops, function definitions, function overloading, and recursion, highlighting their roles in programming. Additionally, it touches on mutability and various string operations like concatenation and substring extraction.

Uploaded by

faberneil60
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

String manipulation is very important for interviews

Primitive data type and primitive class type the difference it the dot (.)
In string + and += is used for appending or concateneation

String a here it will give an error because no objectification of memory is done ie


String a -> Dynamic memory allocation is not given here when you write String a

But if you write ​


String a = new String();

You assing memory without any content ie (null)

If you want to read a word you use .next()

If you want to read a line use .nextLine()

Immutability: once a string created a string cannot be changed, none of its methods changes
the string.

Copy constructor
Deep Copy - Different data in the variables which means if we change word word2 won’t
change its independent (duplication)
String word = new String(“Java”)
String word2 = new String(word)

Shallow Copy - if we make changes in the first word word2 also changes its dependent
(replication)
String word = “java”
String word2 = word;

4 loops are present


1.​ while
2.​ dowhile
3.​ for
4.​ foreach

Substring you can give the start and the end and it will give you the entire string ie
Substring(0, 7)
Abcdefgh = abcddefg
It starts from ith and stops at j-1

Substring is very important and its very easy as well.

Concatenation is + or we use a method .concat() both of them work


Equality

The [Link]() function splits the string whenever there is blank space it separates the word

Compare to library is used to compare

Mutability
-​ append(String s)
-​ Insert
-​ Replace
-​ Delete
-​ reverse

insert(offset, string)
Offset is where you want to insert
String is what string you want to insert

delete (1,3)

[Link]()
String buffer [Link]()

Functions - used for functional programming

Function
Main body

Function is code written away from the main part, called when needed from the main part.
When called, control gets transferred, function gets executed and come back to the script.

1.​ function body


2.​ function prototpye (optional)
3.​ function call

return type name


{​
}

types
1.​ function which does not accept parameter does not return anything​
//giving some info/copyright info
2.​ function which does accept parameters does not return anything*
//used by student max
3.​ function which does accept parameter does return response*
//used in industry max
4.​ function which does not accept parameter does return data
//for getting system info
where to write:

before main()-> then no prototype needed as all is known


after main()-> then prototype is needed

Function overloading is a process of writing multiple functions with same identifier(name) but
different signatures(parameters type/numbers)

Polymorphism means

Function overloading

Recursion is a function calling itself

+ve Looks program smaller and more readable


-ve Takes more memory does program processing slower

You might also like