在玩Java8的Streams-API时,我偶然发现了以下内容:
要将原始包装器classe对象的数组转换为Stream我只需要调用Stream.of(array).但是要转换原始数据类型的数组,我必须.of(array)从相应的包装器(类)流类调用(< - 听起来很傻).
一个例子:
final Integer[] integers = {1, 2, 3};
final int[] ints = {1, 2, 3};
Stream.of(integers).forEach(System.out::println); //That works just fine
Stream.of(ints).forEach(System.out::println); //That doesn't
IntStream.of(ints).forEach(System.out::println); //Have to use IntStream instead
Run Code Online (Sandbox Code Playgroud)
我的问题:
这是为什么?这是否与例如行为Arrays.asList()也适用于包装类数组相关?
我是java的新手,所以如果这听起来绝对愚蠢,请不要降价
好吧如何使用单个扫描仪对象输入此内容
五
你好,你怎么样
欢迎来到我的世界
6 7
对于那些建议的人
scannerobj.nextInt->nextLine->nextLine->nextInt->nextInt,,,
Run Code Online (Sandbox Code Playgroud)
检查出来,它不起作用!
谢谢
如何正确编写以下代码?
public String toString(int[] position, int xOffset, int yOffset) {
String postn = String.format("[%d,%d]", position[0], position[1]);
String movm = String.format("[%d,%d]", xOffset, yOffset);
return (postn, movm);
}
Run Code Online (Sandbox Code Playgroud)
出现以下错误
movm cannot be returned.
Run Code Online (Sandbox Code Playgroud) ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("com/x/y/z.cfg");
File file = new File(url.getPath());
Run Code Online (Sandbox Code Playgroud)
这在从Eclipse运行jar文件时起作用,但在jar文件中运行时不起作用.
java.io.FileNotFoundException:file:\ C:\ Users \nova\Desktop\Matcher.jar!\ c om\x\y\z.cfg
这不是重复的.我检查了所有其他问题,没有有用的信息.
这是我想要处理的输入.我想提取operation属性的值:
<h:outputLink value="#" id="temp_solution">
<rich:componentContro
for="panel"
attachTo="temp_solution"
operation="show"
event="onclick"/>
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
在在线正则表达式测试器的帮助下,我提出了以下正则表达式
(?<=operation=")(\w+)(?=")
Run Code Online (Sandbox Code Playgroud)
为了更有活力,我替换operation为%s所以我可以使用此模板用于不同的情况.但是在尝试使用小型测试程序测试我的"创建"时遇到了一个问题:
public class Main {
private static final String INPUT = "<h:outputLink value=\"#\" id=\"temp_solution\">\n"
+ " <rich:componentControl \n"
+ " for=\"panel\" \n"
+ " attachTo=\"temp_solution\" \n"
+ " operation=\"show\""
+ " event=\"onclick\"/> \n"
+ "</h:outputLink>";
private static final String REGEX_TEMPLATE = "(?<=%s=\")(\\w+)(?=\")";
public static void main(String[] args) throws IOException {
final String actualRegex = String.format(REGEX_TEMPLATE, "operation");
final Pattern pattern = …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的字符串"123456fd.003g",我只想要"."在这种情况下的所有内容"003g".
[^./]+$
Run Code Online (Sandbox Code Playgroud)
我使用上面的正则表达式,但不起作用.
我正在为大学做作业,我对命令行参数和空格有一个快速的问题.
我必须找到一个将在命令行中提供给我们的图像文件.我试图运行我的程序,但因为我的文件位置在文件夹名称中有空格,java假定有多个参数.
因此,当我分配args[0]到String它停止,因为空间的中途.
有没有办法从命令行中取出所有内容并将其分配给String?
提前致谢 :)
项目描述:
我正在编写一个Java程序,其初始当前目录是/ home/user/Desktop.我想在"location/home/user/project /"中运行一个bash命令"du -s"来查找该文件夹的大小,以便我可以在项目中使用该文件夹的大小.我无法发布整个代码,因为它有一些敏感数据.我只是发布了所需的代码.
这就是我所做的: -
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.File;
public class Exec_in_cur_dir {
public static void main(String[] args) {
try {
StringBuffer output = new StringBuffer();
String Command ="cd /home/user/project"; //Bash Command
// create a process and execute
Process p = Runtime.getRuntime().exec(Command);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
System.out.println(output.toString());
} catch (Exception ex) {
ex.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 我有一个HashMap<String, Integer>包含单词及其频率.我现在需要这种转换HashMap成ArrayList刚的话,频率丢弃,但我也想ArrayList被按降序排列的频率词.
有谁知道这样做的有效方法?
String s = "Total Count :2, Correct Count :1, Wrong Count:1, Correct :India is great,, Wrong: where aer you";
Run Code Online (Sandbox Code Playgroud)
我想要的是:
在int变量中.
这对我来说还是个新鲜事,我希望你们能帮助我.
我的代码有什么问题(线程中的异常"main"java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:5)........
public class AAExample {
public static void main(String[] args) {
AAExample nn = new AAExample();
System.out.println(nn.isXOrZ("Pony"));
}
public boolean isXOrZ(String text) {
String lower = text.toLowerCase();
boolean found = false;
int i = 0;
while (!found) {
String letter = lower.substring(i, i +1);
if(letter.equals("z") || letter.equals("x"))
found = true;
i++;
}
return found;
}
}
Run Code Online (Sandbox Code Playgroud)