Skip to content

Tag: java

Delete anything between “<” and “>” in a String

I have try restString = restString.replaceAll(“\&lt;.*\&gt;”, “”); and restString = restString.replaceAll(“\&lt;[^(\&gt)]*\&gt;”, “”);. Both seems don’t work. I don’t know if I could represent the meaning in the regular expression. Answer Make your regex non-greedy: Also I used (?s) to make dot match newlines as well.

Java Fastest way to read through text file with 2 million lines

Currently I am using scanner/filereader and using while hasnextline. I think this method is not highly efficient. Is there any other method to read file with the similar functionality of this? Answer You will find that BufferedReader.readLine() is as fast as you need: you can read millions of lines a second with it. It is more probable that your string

Partition a Set into smaller Subsets and process as batch

I have a continuous running thread in my application, which consists of a HashSet to store all the symbols inside the application. As per the design at the time it was written, inside the thread’s while true condition it will iterate the HashSet continuously, and update the database for all the symbols contained inside HashSet. The maximum number of symbols

Setter methods or constructors

so far I have seen two approaches of setting a variable’s value in Java. Sometimes a constructor with arguments is used, others setter methods are used to set the value of each variable. I know that a constructor initialises an instance variable inside a class once a class is instantiated using the “new” Keyword. But when do we use constructors