Pages

Thursday, 7 March 2019

String Manipulation Interview questions? String concat,replace, substring, trim, lowercase, uppercase? Selenium, Automation core java interview questions?

Interview question for SDET 2023?

SDET Interview Question and Answers.  

Jenkins Interview Questions and Answers

Appium Interview Questions and Answers

Selenium Interview Questions and answers

GIT Interview Questions and Answer

 Pre-requisite: How to install JDK and set Java Home path in Windows and MacOs ?

Ans: Click here for Steps


In Java, a string is a sequence of characters. It is a data type used to store text-based information, such as names, addresses, and messages. Strings are represented by the class "String" in Java.


Why String is Immutable?

In Java, a string is immutable, meaning its value cannot be changed once it is created. Once a string object is created, its value cannot be altered.

The reason for this is to ensure that string objects are thread-safe and to improve performance. Since strings are widely used in Java, immutable strings help to prevent errors that can occur due to changes made to the string value by different threads simultaneously. This ensures that the value of the string remains constant throughout the program execution.

Also, immutable strings can be optimized by the Java Virtual Machine (JVM) for memory usage. Since immutable strings cannot be changed, the JVM can reuse existing string objects, rather than creating new ones each time a modification is made. This can result in better performance and reduced memory usage.

In summary, immutability of strings in Java is a design decision made for the purposes of thread-safety, performance, and memory optimization.


String Manipulation

public class StringManipulation {

    public static void main(String[] args) {
        // Strings are immutable
        String str3 = "java";
        str3.concat("oops");
        System.out.println(str3); // java

        // The result should be assigned to a new reference variable (or same
        // variable) can be reused.
        String concat = str3.concat("value2");
        System.out.println(concat); // value1value2

        // -----------------------String methods-------------------------------------
        String str = "abcdefghijk";

        // char charAt(int paramInt)
        System.out.println(str.charAt(2)); // prints a char - c

        // String concat(String paramString)
        System.out.println(str.concat("lmn"));// abcdefghijklmn

        System.out.println("ABC".equalsIgnoreCase("abc"));// true
        System.out.println("ABCDEFGH".length());// 8

        // String replace(char paramChar1, char paramChar2)
        System.out.println("012301230123".replace('0', '4'));// 412341234123

        // String replace(CharSequence paramCharSequence1, CharSequence
        // paramCharSequence2)
        System.out.println("012301230123".replace("01", "45"));// 452345234523

        // All characters from index paramInt
        // String substring(int paramInt)
        System.out.println("abcdefghij".substring(3)); // defghij
        // 0123456789

        // All characters from index 3 to 6
        System.out.println("abcdefghij".substring(3, 7)); // defg
        // 0123456789

        System.out.println("ABCDEFGHIJ".toLowerCase()); // abcdefghij

        System.out.println("abcdefghij".toUpperCase()); // ABCDEFGHIJ

        System.out.println("abcdefghij".toString()); // abcdefghij

        // trim removes leading and trailings spaces
        System.out.println(" abcd  ".trim()); // abcd
    }
}

Java Interview question Set-1:
SET-01 1-10

Java Interview question Set-2:

SET-02 10-20

Java Interview question Set-3:

SET-03 21-30


What are the two ways to create String?

There are two ways to create a string in Java:

  1. Using String literals - This is the most common and simple way of creating a string in Java. A string literal is a sequence of characters enclosed in double quotes. For example:

String str1 = "Hello World"; String str2 = "Java is awesome";

In this method, a new string object is created each time a string literal is assigned to a variable.

  1. Using String constructor - Another way of creating a string in Java is by using the constructor of the String class. This constructor takes a character array as its argument and creates a new string object with the same character sequence. For example:

char[] charArray = {'H', 'e', 'l', 'l', 'o'}; String str3 = new String(charArray);

In this method, we create a character array and pass it as an argument to the String constructor. This creates a new string object with the same character sequence as the character array.

It is important to note that the second method of creating a string using a constructor is less common than the first method, as it is more verbose and requires more steps.

 *******************************************************************

For any doubts or career guidance, reach out to me 

****************************************

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python


 


 


No comments:

Post a Comment