Tag: hashmap

JSONException:无法使用JSON Array的帮助转换为JSONObject

$ Error :: JSONException:在JSON数组的帮助下,json字符串无法转换为JSONObject 这是导入库 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.os.AsyncTask; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.view.Menu; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; activity_main.xml文件 互联网许可就在这里 […]

如何在获取“无法解决放置符号”错误时向Hashmap添加键和值

我正在使用Android Studio 1.4.1,我刚刚创建了一个Hashmap,并且正在关注如何填充和操作它的教程(在java上)。 但是我得到一个’无法解决符号放置’错误,而“put”命令为红色。 我添加的图像显示了自动完成快照,虽然导入了java.util.HashMap,但自动完成中没有“put”命令。 可用命令也以红色显示。 我尝试使用它们而不是“put”命令。 我一直有这种类型的问题。 有人可以帮忙吗? 先感谢您… import java.util.HashMap; HashMap pozisyon = new HashMap(); pozisyon.put(“SKale”, “a8”);

添加和删​​除ArrayList中的元素设置为hashmap中的值

所以我有一个看起来像这样的文件: 1st 2nd nth e1, v1, 1 e1, v3, 2 e1, v4, 4 e1, v5, 7 e2, v1, 1 ., ., . ., ., . ., ., . 我希望第一列成为hashmap(e1,e2或e3)的键,并将值作为名为“Ratings”的ArrayList,我希望第二列具有它的值(int),在arraylist的第n个索引里面。 到目前为止,这是我的完整代码: import java.util.*; import java.io.*; public class Setup { public static void Setup(String[] args) { String user; int value, location; //Create a Hashmap that holds a […]

不可变对象作为哈希集合中的关键

我已经读过,最好将不可变对象作为HashMap中的键,因为它会缓存生成的哈希码。 为什么不可变对象会默认缓存哈希代码? 将不可变对象作为键是真正的优势吗?

为什么Java HashMap会变慢?

我尝试使用文件内容构建一个地图,我的代码如下: System.out.println(“begin to build the sns map….”); String basePath = PropertyReader.getProp(“oldbasepath”); String pathname = basePath + “\\user_sns.txt”; FileReader fr; Map<Integer, List> snsMap = new HashMap<Integer, List>(2000000); try { fr = new FileReader(pathname); BufferedReader br = new BufferedReader(fr); String line; int i = 1; while ((line = br.readLine()) != null) { System.out.println(“line number: ” + i); […]

如何从arrayList对象中创建所有可能的幂集(或子集)?

说我有以下课程: class A { String name; Double value; } 以及可能具有以下内容的上述类对象的列表: [{f 2.1}, {c 1.1}, {a 0.3}… and so on] [{n 0.5}, {f 1.9}, {x 0.1}, {a 1.9}, {b 1.1}… and so on] … and so on 我想要的只是做以下事情: 1. Building power subsets from the internal list items(NB: skip the single subsets). 2. Push the subset in […]

未知深度java的嵌套哈希映射

我有一个要求,我需要有一个嵌套的hashmap。 但深度将在运行时决定。 例如,如果在运行时,用户说3,那么我的hashmap应该是这样的 HashMap<String, HashMAp<String, HashMap>> 如果他说4那么 HashMap<String, HashMAp<String, HashMap<String, HashMap>>> 有没有办法实现这种function? 其他一些API或工具包??

Android使用包含另一个hashmap的hashmap实现Parcelable对象

这是Android实现Parcelable对象的扩展, 它有hashmap但我的有点不同。 我有这些课程 public class EventDetails implements Parcelable { Private String id; Private String eventName; Private Long eventUnixTime; Private HashMap pickedUser = null; } 和 public class User implements Parcelable { private String email; private String userName; private String userPicture; private Boolean hasLoggedInWithPassword; private HashMap dateJoined = null; public User() { } public User(String email, […]

普通的Json字符串到HashMap

将json to HashMap转换json to HashMap有很多问题。 我希望它对每个人都有帮助。 以下代码将直接值或值Array转换为HashMap 。

使用Iterator循环时将项添加到HashMap

我有一个使用Iterator遍历HashMap的程序,并且在循环内部,我正在添加HashMap – 这导致了ConcurrentModificationException。 我已经看到ListIterator有一个add()函数来处理这个,但Iterator没有。 HashMap设置如下 – HashMap<Pair, Object> 像这样的迭代器 – Iterator<Entry<Pair, Object>> iter; 使用Object(不是真名)是我程序中的一个类。 在我循环或任何其他选项时,有谁知道如何添加到迭代器?