在我在下面发布的代码中,我需要从 HashMap 中删除重复项(最高字母值保留在映射中)并在删除重复项后打印k 个最高值的键。我该怎么做呢?我尝试使用 HashSet 但我很无能为力。
public ArrayList<String> mostOften(int k)
{
ArrayList<String> lista = new ArrayList<String>();
HashMap<String,Integer> temp = new HashMap<String, Integer>();
for(String it : wordList)
{
if(temp.containsKey(it))
temp.put(it, temp.get(it)+1);
else
temp.put(it, 1);
}
temp = sortByValues(temp);
Set<Integer> set = new HashSet<Integer>(temp.values());
System.out.println(set);
return lista;
}
private static HashMap sortByValues(HashMap map)
{
List list = new LinkedList(map.entrySet());
Collections.sort(list, new Comparator()
{
public int compare(Object o1, Object o2)
{
return ((Comparable)((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
}
});
HashMap sortedHashMap = new …Run Code Online (Sandbox Code Playgroud) class FileController extends Controller
{
public function login()
{
/*
* TODO: Handle via CAS
* Hardcoded for demo purposes
*/
Session::put('isLogged', true);
Session::put('index', "123456");
return View::make('login');
}
public function user()
{
if(Session::get('isLogged') == true )
return View::make('user');
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下代码。登录时有一个指向FileControllers @ user的链接。在第二页上,我的会话数据丢失(Session :: all()为空)。是什么导致此问题?