像这样的PHP数组的Java等价物是什么:
$user = array("name" => "John", "email" => "john@mail.com");
Run Code Online (Sandbox Code Playgroud) 当 put() 的参数都不为 null 时,以下代码中会发生 java.util.Hashtable 的空指针异常:
import java.util.Hashtable;
interface action
{
void method();
}
class forclass implements action
{
public void method()
{
System.out.println("for(...){");
}
}
class ifclass implements action
{
public void method()
{
System.out.println("if(..){");
}
}
public class trial
{
static Hashtable<String,action> callfunc;
//a hashtable variable
public static void init()
{
//System.out.println("for"==null); //false
//System.out.println(new forclass() == null); //false
callfunc.put("for",new forclass()); //exception occuring here
callfunc.put("if",new ifclass());
//putting values into the hashtable
}
public static void main(String[] args)
{ …
Run Code Online (Sandbox Code Playgroud) 在阅读本文后出现问题.同步和非同步对象有什么区别?为什么非同步对象比同步对象表现更好?
我有一些旧的第三方Java代码我转换为Java 6.它包含HashTable
实例,标记为过时的集合.我该怎么替换它们?什么是最安全的选择?
我需要去做 :
Dictionary cache;
cache = new Hashtable();
this.getDocument().putProperty("imageCache", cache);
Run Code Online (Sandbox Code Playgroud)
然后我有一个方法:
cache.put(url, picture);
Run Code Online (Sandbox Code Playgroud)
其中picture是一个Image对象.我这样创造:
public Image getSmiley(String smileyName) {
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
ImageIcon myicon = new ImageIcon(getClass().getResource("/ola/smileys/" + smileyName + ".png"));
myicon.paintIcon(null, g, 0, 0);
return img;
}
Run Code Online (Sandbox Code Playgroud)
我已经运行了一个分析,我已经看到,当我将这个方法称为"put"时,应用程序的运行速度令人难以置信.可能是什么原因 ?
非常感谢你.
最好的祝福
我知道散列表可能存在性能问题,但是100万项的散列表怎么能比100项的散列表快?
我想为单个密钥存储多个值,并且必须能够检索特定值.
Java中是否有任何具有此类功能的数据结构?如果是的话,请告诉我.
java ×9
hashtable ×5
hashmap ×2
arrays ×1
collections ×1
dictionary ×1
image ×1
performance ×1
php ×1
put ×1
replace ×1
synchronized ×1