assignment 5 - sidramaqsood/learning GitHub Wiki

Methods with Description

1.char charAt(int index)

Returns the character at the specified index.

2.int compareTo(Object o)

Compares this String to another Object.

3.int compareTo(String anotherString)

Compares two strings lexicographically.

4.int compareToIgnoreCase(String str)

Compares two strings lexicographically, ignoring case differences.

5.String concat(String str)

Concatenates the specified string to the end of this string.

6.boolean contentEquals(StringBuffer sb)

Returns true if and only if this String represents the same sequence of characters as the specified StringBuffer.

7.static String copyValueOf(char[] data)

Returns a String that represents the character sequence in the array specified.

8.static String copyValueOf(char[] data, int offset, int count)

Returns a String that represents the character sequence in the array specified.

9.boolean endsWith(String suffix)

Tests if this string ends with the specified suffix.

10.boolean equals(Object anObject)

Compares this string to the object.

MUTABLE & IMMUTABLE OBJECTS?

ANS..An immutable object is a kind of object whose state cannot be modifier after it is created. in java,object are referd by refrenced is known as immutable object. for example Boolean.int,float,LONG,Short.while mutable can assign multiple values to multiple string and object. state can be altered best example of mutable string builder object can be used.

mutable vs immutable:

ans: mutable object can have their field changed after construction,immutable object cannot.immutable object are simply object whose state(the object data) cannot changed after construction.