+ 1

API

Can I call an API in a java hashtable? If yes then please give me the code🙏

17th Nov 2020, 5:41 AM
Manash Saikia [ 45% Active ]
Manash Saikia [ 45% Active ] - avatar
2 Answers
+ 1
with switch(actionFromTable) import java.util.Hashtable; ... Hashtable<Integer, String> h = new Hashtable<>(); h.put(1, "aaa"); h.put(2, "BBB"); h.put(3, "ccc"); String str=""; for(var kv : h.entrySet() ) { switch(kv.getKey()){ case 1: str += kv.getValue().toUpperCase(); break; case 2: str += kv.getValue().toLowerCase(); break; case 3: str += ">>"+kv.getValue()+"<<"; break; } } System.out.println(str);
17th Nov 2020, 12:11 PM
zemiak
+ 1
import java.util.Hashtable; import java.util.function.Function; ... Hashtable<Integer, Function<String, String> > h = new Hashtable<>(); h.put(1, s -> s.toUpperCase() ); h.put(2, s -> s.toLowerCase() ); h.put(3, s -> ">>"+ s +"<<" ); String str="aaaAAA"; for(var k : h.keySet() ) { System.out.println( h.get(k).apply(str) ); }
17th Nov 2020, 7:56 PM
zemiak