Oracle Interview Question for Software Engineer in Tests


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

package myworks.tricky;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class MyMap {
public static void main(String[] args) {
String val = "value";
String key = null;
Map<String, String> map = new HashMap<String, String>();
map.put("1", "map");
map.put("2", "value");
System.out.println("Intial Map " + map);
if (map.containsValue(val)) {
Set<Entry<String, String>> s = map.entrySet();
Iterator<Entry<String, String>> i = s.iterator();
for (; i.hasNext(); i.next()) {
Entry<String, String> e = i.next();
if (e.getValue().equals(val)) {
key = e.getKey();
System.out.println("The key is " + e.getKey());
}
}
}
if (key.length() > 0) {
map.remove(key);
map.put(val, key);
}
System.out.println("Final Map " + map);
}
}

- Raja June 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In C#:

Object FindKey(Hashtable hash, Object val)
{
	Object ret = null;
	foreach(Object key in hash.keys)
	{
		if(val == hash[key])
		{
			ret = key;
			break;
		}
	}
	return ret;
}

- EugenDu May 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To swap:

...
	ret = key;
	hash.remove(key);
	hash.add(value, key);
...

- EugenDu May 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi, for more Java Interview questions

javadiscover.blogspot.com/search/label/Interview%20Questions

- Anand May 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

code in java:
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a,b,c;

Scanner sc = new Scanner(System.in);
Map <Integer,Integer> ex= new HashMap<Integer,Integer>();
ex.put(1, 10);
ex.put(2, 30);
ex.put(3, 20);
ex.put(4, 40);
System.out.println("the values are"+ ex);
System.out.println("enter key value to search");
a=sc.nextInt();
b=ex.remove(a);
System.out.println("the values are"+ b);
a=b+a;
b=a-b;
a=a-b;
ex.put(a,b);
System.out.println("the values are"+ ex);
}

}

- Anonymous May 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a,b,c;

Scanner sc = new Scanner(System.in);
Map <Integer,Integer> ex= new HashMap<Integer,Integer>();
ex.put(1, 10);
ex.put(2, 30);
ex.put(3, 20);
ex.put(4, 40);
System.out.println("the values are"+ ex);
System.out.println("enter key value to search");
a=sc.nextInt();
b=ex.remove(a);
System.out.println("the values are"+ b);
a=b+a;
b=a-b;
a=a-b;
ex.put(a,b);
System.out.println("the values are"+ ex);
}

}

- ishwar May 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Object findKey (HashMap map, Object value) {
		for (Object key: map.keySet()) {
			if (map.get(key) == value) {
				return key;
			}
		}
		return null;
	}
	
	void swap (HashMap map, Object key) {
		Object value = map.get(key);
		
		map.remove (key);
		map.put (value, key);

}

- Pawan August 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package practice;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class prac {


public static void find(String value,Map m1)
{

Set s = m1.entrySet();

Iterator i = s.iterator();

String Key;
String Value;
Map.Entry m ;
while(i.hasNext())
{
m = (Map.Entry)i.next();
if(m.getValue().equals(value))
{
System.out.println(m.getKey());
}

Key = m.getKey().toString();
Value = m.getValue().toString();

m1.remove(m.getKey());
m1.put(Value, Key);


}

System.out.println("after swapping: "+m1);

}



public static void main(String args[])
{
Map m1 = new ConcurrentHashMap();

m1.put("1", "aa");
m1.put("2", "bb");
m1.put("3", "cc");

find("cc",m1);

}






}

- Ravi Kiran September 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void getKeyandReplace(Object key ,Map map){
	  if(key!=null&&map.containsKey(key)){
		Object value= map.get(key);
		map.remove(key);
		map.put(value,key);
	  }
	}

- Anonymous October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void findKey(String s)
{
HashMap keyValues = new HashMap();
keyValues.put(new Integer(1), new String("One"));
keyValues.put(new Integer(2), new String("Two"));
keyValues.put(new Integer(3), new String("Three"));
keyValues.put(new Integer(4), new String("Four"));

Iterator iter = keyValues.entrySet().iterator();

while (iter.hasNext()) {
Map.Entry entry = (Entry) iter.next();
if (entry.getValue().equals(s)) {
System.out.println(((Integer) entry.getKey()).intValue());
}
}
}

- Geethu May 14, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More