Java Programming and Technical Programming

What is the output of the following program?

import java.util.Arrays;

class Test
{
public static void main(String args[])
{
String[] cities = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] metros = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] capitals = cities;
System.out.println("cities == metros : " + (cities == metros));
System.out.println("cities == capitals : " + (cities == capitals));
System.out.println("cities.equals(metros) : " + cities.equals(metros));
System.out.println("cities.equals(capitals) : " + cities.equals(capitals));
System.out.println("Arrays.equals(cities, metros) : " + Arrays.equals(cities, metros));
System.out.println("Arrays.equals(cities, capitals) : " + Arrays.equals(cities, capitals));
}
}


A. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : false
Arrays.equals(cities, capitals) : true

B. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true

C. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true

D. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : false

Read Solution (Total 1)

Java Other Question

public String makingStrings()
{
String str = "Welcome";

str = str.substring(1, 5);

str = str.toUpperCase();

return str;
}

How many String objects are created in the heap when this method is invoked?

A. 4
B. 2
C. 3
D. 1
Consider the below statements.

Statement 1 : Matcher class interprets the pattern in a String

Statement 2 : Matcher class matches the regular expression against the text provided

Which of the following is true?

A. Statement 2 alone is correct.
B. Both Statement 1 and 2 are incorrect.
C. Statement 1 alone is correct.
D. Both Statement 1 and 2 are correct