相关疑难解决方法(0)

Java LinkedHashMap获取第一个或最后一个条目

我使用过,LinkedHashMap因为重要的是键在地图中输入的顺序.

但现在我想首先获得key的值(第一个输入的条目)或最后一个.

如果有喜欢的方法first()last()或类似的东西?

我是否需要一个迭代器才能获得第一个键入口?这就是我使用的原因LinkedHashMap!

谢谢!

java dictionary linkedhashmap

123
推荐指数
6
解决办法
11万
查看次数

确定性是什么意思?

我正在阅读Java Hashmap文档,但我不明白这句话.

请注意,HashMap的迭代顺序是非确定性的.如果您想要确定性迭代,请使用LinkedHashMap.

确定性是什么意思?

java deterministic

34
推荐指数
5
解决办法
7697
查看次数

如何对Java Hashtable进行排序?

我将一些数据插入Java Hashtable.如果我从Hashtable读取数据,它的返回顺序与我插入的顺序不同.如何从Hashtable获取有序数据?

我使用以下代码从哈希表中获取值:

// Get a set of the entries
Set set = hsUpdateValues.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while (i.hasNext()) {
    Map.Entry me = (Map.Entry) i.next();            
    System.out.print(
        "Key : " + me.getKey()
        + ", Value: " + me.getValue()
    );
}
Run Code Online (Sandbox Code Playgroud)

java sorting maps hashtable

8
推荐指数
4
解决办法
6万
查看次数

从 HashMap 中获取第一个和最后一个元素

我有以下代码,我希望能够从 Map 中获取第一个和最后一个元素并将每个元素分配给一个字符串。

String result1stElement = null;
String resultLastElement = null;

Map<String, String> result = new HashMap<String, String>();
result = myModel.getSampleResults();
Run Code Online (Sandbox Code Playgroud)

有任何想法吗。

提前致谢。

java hashmap

1
推荐指数
1
解决办法
2万
查看次数

Java从Hashmap获取最后一个键

以前,如果我的问题很经典,我表示歉意。但是因为我刚刚学习了android的Java编程,我并没有真正理解命令。

我目前正在使用代码部分制作一个应用程序,如下所示:

Map<Integer, CompTypes> mapCompTypes = new java.util.HashMap();

class CompTypes
{
    int androidId;
    AndroidViewComponent component;
    String text;
    String type;
    CompTypes(int androidId, AndroidViewComponent component, String type, String text)
    {
        this.androidId = androidId;
        this.component = component;
        this.type = type;
        this.text = text;
    }
}

public void SendMessage(HVArrangement container, String message, String dateTime, int fontSize, int fontColor, int alignment, int startid)
{
    int id = Integer.parseInt(ChatBox.this.GetLastId());
    TextBox comp = new TextBox(vertical);
    comp.getView().setId(id);
    comp.Text(message);
    comp.FontSize(fontSize);
    comp.TextColor(fontColor);
    comp.MultiLine(true);
    comp.Enabled(false);
    comp.RequestFocus();
    mapCompTypes.put(Integer.valueOf(id), new CompTypes(id, comp, compType, …
Run Code Online (Sandbox Code Playgroud)

java android hashmap

1
推荐指数
1
解决办法
8386
查看次数