所以我有大量(我的意思是大量)数组。它有超过 500000 行。 每行都以一些我不需要的废话开头。我需要的是第 64 个符号之后的所有内容(需要第 65 个符号)。每行都是相同的,但第 64 个符号之后每行长度不同。我如何获得 65 及以上的符号...? 如果其他所有内容都被删除,但第 64 个字符之后的那些符号保留在数组中,对我来说没关系。
for (int i = 0; i < stringArrAC.length; i++)
{
if (i<=64)
{
stringArrAC[i] = null;
break;
}
}
类似这样的事情吗?但它不工作... 感谢帮助。 :)
编辑..我需要更多帮助 所以我回来了..
我按照我想要的方式得到了 500000 多行..现在我需要找到每行中的倒数第二个单词(它们被空格分开)并找到其中 3 个最受欢迎的单词并找出其中有多少个。 ...你能以任何方式帮助我吗?
data example:
abcd i
asd ffdds abcd ddd ?
abcd ffdds asd ddd i
ddd abcd i
a f g w e a asdfasdasdas fdd i
我需要的答案:
abcd 2
ddd 2
fdd 1
or
2 abcd
2 ddd
1 fdd
这是我的代码
public class asdf {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
String str;
List<String> list = new ArrayList<String>();
while((str = in.readLine()) != null){
if (str.startsWith(" ")&& str.endsWith("i")||str.endsWith("?")) {
list.add(str);
}
}
String[] stringArr = list.toArray(new String[0]);//for backup
String[] stringArrAC = list.toArray(new String[0]);
for (int i = 0; i < stringArrAC.length; i++)
{
stringArrAC[i] = stringArrAC[i].substring(63);
}
//String[] stringArrLAST = (new String[0]);
for (int i = 0; i < stringArrAC.length; i++)
{
// THIS IS WHERE I DONT KNOW WHAT TO DO
}
try
{
PrintWriter pr = new PrintWriter("output.txt");
for (int i=0; i<stringArrAC.length ; i++)
{
pr.println(stringArrAC[i]);
}
pr.close();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("No such file exists.");
}
}
最佳答案
假设它是一个字符串数组,下面的代码应该这样做
for (int i = 0; i < stringArrAC.length; i++) {
stringArrAC[i] = stringArrAC[i].substring(64);
}
关于Java,在字符r之前截断数组行。 X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30991705/