You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java新手实现提取最长字符串功能遇cannot find symbol错误求提示

提示:解决"cannot find symbol: variable list"错误

Hey there, let's break down what's going on here with your code:

  • First off, the error you're seeing is all about variable scope. Right now, you're declaring your ArrayList<String> list inside the first for loop. That means each time the loop runs, a brand new list gets created, and once that iteration of the loop finishes, that list is no longer accessible outside of it. When you try to use list later (outside the loop), the compiler has no idea what you're talking about because it doesn't exist in that scope.
  • A quick fix hint: Move the line where you initialize list before the first for loop. That way, it's created once and accessible throughout the entire method.
  • One extra little thing to double-check: In your inner loop, you're using inputArray[i] to check the length, but that's just the element from the outer loop's current iteration. You probably want to be checking each element in the array (inputArray[j]) instead to make sure you're adding all the longest strings.

内容的提问来源于stack exchange,提问作者Szewniak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:20:35