我有一个程序,它创建一个队列,将对象排入队列,然后如果队列不为空,则逐个将它们出列.我遇到的问题是每次检查时队列都是空的.在将每个对象排入队列后在队列上调用打印,并且它打印队列的内容就好了.
import java.util.*;
import java.io.*;
public class Processor2
{
private LinkedQueue queue = new LinkedQueue();
private int time = 0;
private int count = 100;
private int amount = 0;
private PrintWriter out;
private Person temp;
private boolean var;
private Random randomNum = new Random();;
private String turn;
private int popCount=0;
private int loopCount =0;
public void start()
{
amount = randomNum.nextInt(5);
amount += 5;
pop(amount, time);
sim();
}
public void pop(int num, int time)
{
for(int i=1; i<=num; i++) …Run Code Online (Sandbox Code Playgroud) 我正在使用API来检索JSON格式的某些温度和位置值.我在纯文本缓存文件中写输出.
然而,温度站可能无法报告温度值,在这种情况下,我的输出将是空行(\n).我想通过显示非报告站的"N/A"来处理这种情况.
这是一个典型的缓存文件,第一个站报告温度和位置,第二个站关闭(报告两个空行):
27.6
Napoli-Posillipo
(an empty line)
(an empty line)
Run Code Online (Sandbox Code Playgroud)
我尝试过:
$display = file($cachename);
$temperature[0] = $display[0];
$location[0] = $display[1];
$temperature[1] = $display[2];
$location[1] = $display[3];
$temp_avg = (($temperature[0]+$temperature[1])/2); //average temperature
if($temperature[0] = "\n"){ //if weather station is not reporting data
$temperature[0] = "N/A";
$temp_avg = "N/A";
}
if($temperature[1] = "\n"){
$temperature[1] = "N/A";
$temp_avg = "N/A";
}
echo "<div id='temperature'><b>".$temperature[0]."</b>°C (".$location[0].") | ";
echo "<b>".$temperature[1]."</b>°C (".$location[1].") | ";
echo "<b>".$temp_avg."</b>°C (avg) | ".$minutes."m".$secondsleft."s ago</div>";
Run Code Online (Sandbox Code Playgroud)
但是,即使第一个工作站正确报告其温度值,我仍然会为两个工作站获得"N/A".
N/A°C(Napoli-Posillipo)| N/A°C()| N/A°C(平均)| …
我有一个问题,我知道如何检查文件夹是否为空,但我总是得到一个错误,当我检查文件夹是否为空循环,这是我的代码不起作用的示例.
String sdcard = Environment.getExternalStorageDirectory().toString();
File file = new File(sdcard);
File subFiles[] = file.listFiles();
for(int i=0; i<subFiles.length; i++) {
File subFile = new File(sdcard +"/"+ subFiles[i].getName());
if(subFile.isDirectory() && subFile.listFiles().length==0) {
}
}
Run Code Online (Sandbox Code Playgroud)
我总是在我的情况下得到错误.
为什么
if (!empty(constant('MY_CONST')))
Run Code Online (Sandbox Code Playgroud)
抛出这个错误
Fatal error: Can't use function return value in write context
Run Code Online (Sandbox Code Playgroud)
我该如何解决呢?
我有相关的一个简单的问题==null和=="",我想每个人都知道这个问题.
这是一个例子:
@SuppressWarnings("unchecked")
public void reorderingCriteia() {
ListModelList<ReorderData> headerList = new ListModelList<ReorderData>();
List<String> headerId = new ArrayList<String>();
String userReorderSelection = Services.userPreferenceService().getUserPreference().getUserOption("PROCESS_CHECKLIST_COLUMN_REORDER");
if (userReorderSelection == null || userReorderSelection == "") {
int i = 0;
for (ReorderData rd : availableReorderList) {
headerList.add(rd);
headerId.add("" + i);
i++;
}
folderProcessModel.setHeaderList(headerList);
folderProcessModel.setHeaderId(headerId);
} else {
headerList = ReorderDialogViewModelNew.jsonStringToList("FOLDER_PERMIT_LIST_COLUMN_REORDER", userReorderSelection, false);
headerId = compHelper.intializeSequnce(headerList, folderProcessModel.getAvailableHeaders());
folderProcessModel.setHeaderList(headerList);
folderProcessModel.setHeaderId(headerId);
}
}
Run Code Online (Sandbox Code Playgroud)
我有一些问题:
这段代码使用if (userReorderSelection == null || userReorderSelection == "").我能用这个条件if …
在JDK文档中,它声明String方法isEmpty()对于任何长度为0 的字符串都是true.
对于空字符串来说,这显然是正确的"".
是否还有其他字符串?我测试过换行符和回车符,它们有一个长度.我还没有测试带有附加退格的字符.
编辑:我很欣赏以下所有好答案中的所有其他信息,但我已经接受了我认为最直接的答案.
我有以下JSON:
{
"BTC_1CR": [],
"BTC_ABY": [],
"BTC_AC": [],
"BTC_ADN": [],
"BTC_PLX": [
{
"orderNumber": "4953620",
"type": "sell",
"rate": "0.00000597",
"amount": "653.85639346",
"total": "0.00390352",
"date": "2014-05-30 22:44:40"
}
],
"BTC_PMC": [],
"BTC_PPC": []
}
Run Code Online (Sandbox Code Playgroud)
我需要摆脱空的[]元素..
我正在创建一个应用程序,它需要为每个用户编写一个文件(采用JSON格式).
该应用程序成功创建了该文件,但它是空的.在代码中我添加了一个更精细的输出,以查看转换后的JSON字符串是什么样的,我注意到它已完成(它包含所有内容,因此转换正常).但该字符串不存在于文件中.
//create a new FileWriter C:/.../42.guser
FileWriter writer = null;
//for every User
for(int i=0; i<users.size(); i++) {
try {
File f = new File(Users.usersDir.getPath()+"/"+i+".guser");
//Create new file
f.createNewFile();
writer = new FileWriter(f);
//convert to json and write to file. Here we get the object with KEY = keys[i].
String stringedUsr = gson.toJson(users.get(keys[i]));
logger.finer("Converted user: \""+stringedUsr+"\""); //Output seems ok
//Write (NOT WORKING)
writer.write(stringedUsr);
logger.fine("Wrote updated user \""+keys[i]+"\" to file "+f.getCanonicalPath());
} catch (IOException e) {
FAILS++;
e.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) Java 11isBlank()为java.lang.String类添加了一个新的实例方法 .
现有方法isEmpty和新增isBlank()方法之间的基本区别是什么?
我正在尝试使用VBA .Find函数连续查找第一个非空单元格。代码如下:
Sub test()
With Selection
Set firstNE = .Find(what:="*", LookIn:=xlValues)
End With
Debug.Print firstNE.Address
End Sub
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是当我选择范围(例如B4:F4)并且该范围内的所有单元格都不为空时,它将返回C4而不是B4。
当B4不为空,然后下一个非空为例如E4时,也会发生同样的情况,它返回E4而不是B4。
如果除B4以外的所有选择均为空,则仅返回B4。
有人可以向我解释吗?
顺便说一句。我不想使用IsEmpty + loop,因为它花费了太多时间来处理我的数据。