+ 1
API
Can I call an API in a java hashtable? If yes then please give me the code🙏
2 odpowiedzi
+ 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);
+ 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) );
}