我试图通过使用Javascript的大写字母拆分字符串,
我试图做的例子:
"HiMyNameIsBob" -> "Hi My Name Is Bob"
"GreetingsFriends" -> "Greetings Friends"
Run Code Online (Sandbox Code Playgroud)
我知道这个str.split()方法,但我不知道如何使这个函数使用大写字母.
我试过了:
str.split("(?=\\p{Upper})")
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用,任何帮助都会很棒.
我有一个包含多个字符串数组的hashmap.我试图输出hashmap的一个数组中的每个元素,但我似乎总是得到
java.lang.NullPointerException
Run Code Online (Sandbox Code Playgroud)
这是我的代码,
import java.util.HashMap;
public class TestApp {
private static HashMap<String, String[]> subjects;
public TestApp() {
HashMap<String, String[]> subjects = new HashMap<String, String[]>();
subjects.put("calculus",new String[] {"math","logic"});
subjects.put("chemisty",new String[] {"ions","electrons"});
subjects.put("biology",new String[] {"life","bacteria"});
}
public static void main(String[] args){
for(String s:subjects.get("biology")){
System.out.println(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止这个问题?
我创建了一个名为的多维数组current_map.
我想访问current_map:
current_map[0][1]
但是我收到错误:
错误:需要数组,但找到了String
这是我的代码,为您的观赏乐趣
import java.util.*;
import java.util.Map.Entry;
import java.util.ArrayList;
public class TestApp {
private ArrayList<String[]> current_map = new ArrayList<String[]>();
public TestApp() {
current_map.add(new String[] { "0","0","0" });
current_map.add(new String[] { "0","Q","0" });
current_map.add(new String[] { "0","0","0" });
}
public String getValue(int X,int Y){
String[] obj_map = current_map.toArray(new String[current_map.size()]);
return obj_map[X][Y]; // for example, getValue(2,2), should give "Q"
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能阻止这个问题呢?