String and Arrayiy

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1.Differentiate between String and char.

Ans: -
String char

(i) String is a class under java.lang package. (i) char is a kind of primitive data type.

(ii) String does not occupies any fixed size of memory. (ii) char occupies 2 bytes of memory.

(iii) String data represents with double quotation (" (iii) char data represents with single quotation ('
"). ').

2. Differentiate between String and StringBuffer.


Ans: -
String StringBuffer

(i) String represents fixed length. (i) StringBuffer represents length of changing values.

(ii) Objects are immutable i.e., once created (ii) Objects are mutable i.e., they can be manipulated
they cannot be changed. and modified as desired.

3. Differentiate between isUpperCase() and toUpperCase() method.


Ans: -
isUpperCase() toUpperCase()

(i) It is used to check whether a given character is in (i) It is used to convert any string or character
upper case or not. into upper case.

(ii) Return type is boolean. (ii) Return type is String.

4. Differentiate between next() function and nextLine() function.


Ans: - next() function allows user to input a string as a single word whereas,
nextLine() function accepts String as a text line.
5. Differentiate between equals() and compareTo() function.
Ans: -
equals() compareTo()

(i) This function only checks whether two (i) This function checks whether a String is equal, bigger or
Strings are identical or not. smaller than other String or not.

(ii) It results in boolean type value i.e.,


(ii) It results in an integer type value.
true/false.

6. What is the difference between == and equals() function.


Ans: - == is a relational operator which is used to check equality with int,
double, char values. equals() is a String function which is used to check
equality with two or more String data.
7. What is the difference between length() and length?
Ans: - length() is a String function which counts the length of a String i.e., the
total number of characters present in a String. length is a property of array
which returns the total number of elements present in an array.
8. What is an array?
Ans: - An array is a group of similar data types that are referenced by a
common name. Arrays can be of one or more dimensions.
9. Differentiate between searching and sorting.
Ans: - Searching allows us to find data that meets specific criteria. Whereas,
sorting allows us to organize some data, based upon some order (Ascending
or Descending).
10. Differentiate between Bubble sort and Selection sort.
Ans: -
Bubble sort Selection sort

(i) Adjacent element is compared and (i) Largest element is selected and swapped with the last element
swapped. (Ascending order).

(ii) Less efficient than Selection sort. (ii) Comparatively more efficient than Bubble sort.

(iii) Slower than Selection sort. (iii) Faster than Bubble sort.

11. Differentiate between Linear Search and Binary Search.


Ans: -
Linear Search Binary Search

(i) Linear search works on sorted and


(i) Binary search takes place only on sorted data items.
unsorted data items.

(ii) The search begins at the start of (ii) An array divided into two halves and then the desired data item
an array i.e., from 0th index. is searched either in the first half or in the second half.

(iii) Faster method than Binary


(iii) Slower method than Linear search.
search.

12. Differentiate Single Dimensional Array (SDA) and Double


Dimensional Array (DDA).
Ans: -
Single Dimensional Array (SDA) Double Dimensional Array (DDA)

(i) It is represented along X-axis. (i) It is represented along X-axis and Y-axis.

(ii) The variables with same name have (ii) The variables with same name have two types of subscript
single subscript. representing row and column.

You might also like