Java, cut off array line before charactern nr. X

93 views Asked by At

So i have massive(i mean massive) array. It has over 500000 lines. Each line starts with some bs that i don't need. What i need is EVERYTHING after 64th symbol(65th symbol is needed). It's the same for every line, but after 64th symbol each line lenght is different. How do i get symbols form 65 and on...? It's ok by me if everything else is deleted but those symbols after 64th character stay in the array.

for (int i = 0; i < stringArrAC.length; i++)
        {
            if (i<=64)
            {
                stringArrAC[i] = null;
                break;
            }
        }

something like this? but its not working... Thanks for help. :)

EDIT.. I NEED MORE HELP So im back..

i GOT MY 500000 plus lines to the way i want them.. now i need to find second to last word in each line(they are divided by space) and find 3 most popular of them and find how many are there.... Can You help me in any way?

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

answer that i need:

abcd 2
ddd 2
fdd 1

or
2 abcd
2 ddd
1 fdd

This is my code

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.");
        }
                }  
2

There are 2 answers

1
Raman Shrivastava On BEST ANSWER

Assuming it is an String array, below code should do

for (int i = 0; i < stringArrAC.length; i++) {
    stringArrAC[i] = stringArrAC[i].substring(64);
}
0
Kevin W. On

If you're looking to get the end of a string, you could just use the substring() method. In this case, it would look like

stringMinus64 = stringArrAC.substring(65)

You wouldn't even need the for loop. documentation is here: http://www.tutorialspoint.com/java/java_string_substring.htm