假设如下:
String example = "something";
String firstLetter = "";
Run Code Online (Sandbox Code Playgroud)
是否存在差异,需要注意以下firstLetter可能影响绩效的分配方式; 哪个最好,为什么?
firstLetter = String.valueOf(example.charAt(0));
firstLetter = Character.toString(example.charAt(0));
firstLetter = example.substring(0, 1);
Run Code Online (Sandbox Code Playgroud)
第一个字母作为a返回的原因String是它在Hadoop中运行,并且需要分配给Text类型的字符串,firstLetter将作为a key从map()方法输出,例如:
public class FirstLetterMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
String line = new String();
Text firstLetter = new Text();
IntWritable wordLength = new IntWritable();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
line = value.toString();
for (String word : line.split("\\W+")){
if …Run Code Online (Sandbox Code Playgroud) 我正在创建一个EditText可以在用你的昵称写 @ 时提及其他用户的内容,例如在 Facebook、Instagram、Twitter 等上。例如,在文本“今天@john 和@jane 吃了蛋糕”中,我想创建一个ArrayList与数值“约翰”和“简”。我试过这个,但没有用。该怎么做才能做到这一点?