在PHP中,我们(至少是优秀的程序员)总是以小写字母开始一般变量名,但是使用大写字母的类变量/对象来区分它们.同样,我们使用小写字母开始一般文件名,但包含带大写字母的Classes的文件.
例如:
<?php
$number=123;
$string="a string";
$colors_array=array('red','blue','red');
$Cat=New Cat();
?>
Run Code Online (Sandbox Code Playgroud)
这些约定在java中是相同的,即以大写字母开头的对象,但是小写的其余部分,或者在我在其他地方阅读时,一切都以小写字母开头?
我有一个字符串列表,我浏览它并计算"x"字符串的数量如下,但计数不打印我预期的值:
ArrayList<Integer> list = new ArrayList<Integer>();
List<String> strings = table.getValue(); //this gives ["y","z","d","x","x","d"]
int count = 0;
for (int i = 0; i < strings.size(); i++) {
if ((strings.get(i) == "x")) {
count++;
list.add(count);
}
}
System.out.println(list);
Run Code Online (Sandbox Code Playgroud)
这给[]它应该是2因为我有2次出现"x"