我怎么能转换String成intJava中?
我的字符串只包含数字,我想返回它代表的数字.
例如,给定字符串"1234",结果应该是数字1234.
我有一个HashMap:
private HashMap<TypeKey, TypeValue> example = new HashMap<TypeKey, TypeValue>();
Run Code Online (Sandbox Code Playgroud)
现在我想要浏览所有值并打印它们.
我写了这个:
for (TypeValue name : this.example.keySet()) {
System.out.println(name);
}
Run Code Online (Sandbox Code Playgroud)
它似乎不起作用.
问题是什么?
编辑:另一个问题:这个集合是零基础吗?我的意思是如果它有1个键,值大小是0还是1?
假设我有一个名为的类Class,
我想创建一个新的ArrayList,它的值将是类型Class.
我的问题是:我该怎么做?
我无法从Java Api中理解.
我试过这个:
ArrayList<Class> myArray= new ArrayList ArrayList<Class>;
Run Code Online (Sandbox Code Playgroud) 我有一个非常奇怪的问题.写完之后:
for (File f : currentFile.listFiles()) {
if (f.isDirectory()){
System.out.println(f.getName()+"\t"+"Dir\t"+Command.getpremission(f)+"\t"+f.getTotalSpace());
}
else{
System.out.println(f.getName()+"\t"+"File\t"+Command.getpremission(f)+"\t"+f.getTotalSpace());
}
Run Code Online (Sandbox Code Playgroud)
我看到这印:
see.txt File rw 267642728448
see1.txt File rw 267642728456
see2.txt File rw 267642728448
Run Code Online (Sandbox Code Playgroud)
为什么标签出现问题?
是否有任何方法或快速方法来检查数字是否是Java中的整数(属于Z字段)?
我想可能会从四舍五入的数字中减去它,但我没有找到任何可以帮助我的方法.
我应该在哪里检查?整数Api?
我正在尝试编写一个将数字转换为二进制的代码,这就是我写的内容.它给了我Eclipse中的几个错误,我不明白.这有什么问题?还有其他建议吗?我想学习和听取任何修复它的意见.谢谢.
public class NumberConverte {
public static void main(String[] args) {
int i = Integer.parseInt(args);
public static void Binary(int int1){
System.out.println(int1 + "in binary is");
do {
System.out.println(i mod 2);
} while (int1>0);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误消息:
parseInt(String)类型中的方法Integer不适用于参数(String[])(" 上的语法错误; 预期)" 上的语法错误; 预期void 是变量的无效类型 Binaryint [] nir1 = new int [2];
nir1[1] = 1;
nir1[0] = 0;
int [] nir2 = new int [2];
nir2[1] = 1;
nir2[0] = 0;
boolean t = nir1.equals(nir2);
boolean m = nir1.toString().equals(nir2.toString());
Run Code Online (Sandbox Code Playgroud)
为什么m和t都是假的?在Java中比较2个数组的正确方法是什么?
这是我的代码的一部分
try{
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
while ((line= in.readLine())!="exit"){
System.out.println("Enter command");
line=in.readLine();
Command currentCommand=new Command(line);
File currentFile= new File(currentCommand.getLsPath());
Run Code Online (Sandbox Code Playgroud)
该方法currentCommand.getLsPath()返回一个字符串,这是File Constracture的修饰,但我仍然收到此错误:File cannot be resolved to a type
问题是什么?
我需要这样做:
while (result2.charAt(j)!='\'){
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误说:Invalid character constant.
为什么?我怎么能克服它?