Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在流中查找非重复字符_Java_Hashmap_Queue - Fatal编程技术网

Java 在流中查找非重复字符

Java 在流中查找非重复字符,java,hashmap,queue,Java,Hashmap,Queue,流中的第一个非重复字符。我试图用极客帮极客解决这个问题,但这是一个错误。有人能帮我吗? import java.util.*; 导入java.lang.*; 导入java.io.*; GFG类{ 公共静态void firstnonrepeatingcharacteristream(char[]流){ HashMap h=新的HashMap(); 队列q=新的LinkedList(); for(int i=0;i0){ int N=sc.nextInt(); 字符流[]=新字符[N]; 对于(i

流中的第一个非重复字符。我试图用极客帮极客解决这个问题,但这是一个错误。有人能帮我吗?

import java.util.*;
导入java.lang.*;
导入java.io.*;
GFG类{
公共静态void firstnonrepeatingcharacteristream(char[]流){
HashMap h=新的HashMap();
队列q=新的LinkedList();
for(int i=0;i0){
int N=sc.nextInt();
字符流[]=新字符[N];
对于(int i=0;i
我得到这个错误:

Compilation Error

prog.java:12: error: cannot find symbol
       
 h.put(stream[i],h.getorDefault(stream[i],0)+1);
                         ^
  
symbol:   method getorDefault(char,int)
  
location: variable h of type HashMap<Character,Integer>

1 error
编译错误
prog.java:12:错误:找不到符号
h、 put(流[i],h.getorDefault(流[i],0)+1);
^
符号:方法getorDefault(char,int)
位置:HashMap类型的变量h
1错误
第一个错误

prog.java:12: error: cannot find symbol

h.put(stream[i],h.getorDefault(stream[i],0)+1); 
是因为Or没有像它应该的那样大写。应改为:

h.put(stream[i],h.getOrDefault(stream[i],0)+1);
至于其他错误,则是由于您试图将对象不正确地转换为字符所致:

char c=q.peek();
以及不正确地尝试将字符串转换为字符:

stream[i]=sc.next();

我希望这对面试准备有帮助,祝你好运

这是一个小错误,方法应该命名为
getOrDefault