String Class

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Boolean equal

checks the equality of string with the given object.

String concat()

concatenates the specified string

String replace(char old, char new)

replaces all occurrences of the specified char value.

Immutable String objects

unmodifiable or unchangeable.

What is String in java?

An object that represents a sequence of characters. Java.String class is used to create a string object.

boolean is empty

Check if string is empty.

Is String a primitive type or derived type?

String is a derived type. its a class

Explain difference between sting, String Buffer and String Builder

Strings are immutable and SBuffer, SBuilder are mutable means can change the content in opbject

What is the difference between =,==,.equal

== means Object reference memory .equl()--- Content or value of the object

How many objects will be created in the following code and where they will be stored in the memory? String s1 = "abc"; String s2 = "abc";

Only one

String class methods: int length()

Returns string length

Boolean contains

Returns true of false after matching the sequence of char value.

What is string constant pool

String Constant Pool is the memory space in heap memory specially allocated to store the string objects created using string literals

how many ways you can create string objects in java?

String s1 = new String("abc"); //Creating string object using new operator String s2 = "abc"; //Creating string object using string literal

java program to reverse a string

StringBuffer sbf = new StringBuffer("MyJava"); System.out.println(sbf.reverse()); Iterative method: String str = "MyJava"; char[] strArray = str.toCharArray(); for (int i = strArray.length - 1; i >= 0; i--) { System.out.print(strArray[i]); //Output : avaJyM }


Ensembles d'études connexes

Geography 107 Exam 2 HW Questions

View Set

Secured Transactions Priority Practice Qs

View Set

RESEARCH: TEXT EXPLICIT, TEXT IMPLICIT, SCRIPT SPECIFIC

View Set

Constitutional Law Unsure/Incorrect Question

View Set

Sports and Play: Chapter 14: Sports in High School and College

View Set

Robert Green - Art History 20th Century Exam 2 (Movement Characteristics)

View Set