本文整理汇总了Java中java.util.Optional.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.toString方法的具体用法?Java Optional.toString怎么用?Java Optional.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Optional
的用法示例。
在下文中一共展示了Optional.toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: show
import java.util.Optional; //导入方法依赖的package包/类
/**
* Shows the alert
* @return String - Whatever the user entered. Null if nothing was entered
*/
public String show(){
alert.initStyle(style);
alert.setHeaderText(header);
alert.setContentText(question);
Optional<String> result = alert.showAndWait();
if (result.isPresent()){
return result.toString();
} else return null;
}
示例2: testGetDataOutputMkvTagNameWithPathFileWrite
import java.util.Optional; //导入方法依赖的package包/类
@Test
public void testGetDataOutputMkvTagNameWithPathFileWrite() throws IOException {
InputStreamParserByteSource parserByteSource = getInputStreamParserByteSource("output_get_media.mkv");
List<EBMLTypeInfo> mkvTypeInfosToRead = new ArrayList<>();
mkvTypeInfosToRead.add(MkvTypeInfos.TAGNAME);
StreamingMkvReader streamReader =
new StreamingMkvReader(true, mkvTypeInfosToRead, parserByteSource);
Path tmpFilePath = Files.createTempFile("StreamingMkvOutputGetMedia","output.txt");
int count = 0;
try (BufferedWriter writer = Files.newBufferedWriter(tmpFilePath,
StandardCharsets.US_ASCII,
StandardOpenOption.WRITE,
StandardOpenOption.CREATE)) {
while (streamReader.mightHaveNext()) {
Optional<MkvElement> mkvElement = streamReader.nextIfAvailable();
if (mkvElement.isPresent()) {
if (mkvElement.get().getClass().equals(MkvDataElement.class)) {
count++;
}
String elementString = mkvElement.toString();
writer.write(elementString, 0, elementString.length());
writer.newLine();
}
}
} finally {
Files.delete(tmpFilePath);
}
Assert.assertEquals(5*12, count);
}