Skip to content
Advertisement

Finding second occurrence of a substring in a string in Java

We are given a string, say, “itiswhatitis” and a substring, say, “is”. I need to find the index of ‘i’ when the string “is” occurs a second time in the original string. String.indexOf(“is”) will return 2 in this case. I want the output to be 10 in this case. Answer Use overloaded version of indexOf(), which takes the starting index

Java-get most common element in a list

Does Java or Guava have something that will return most common element in a list? [1,3,4,3,4,3,2,3,3,3,3,3] return 3 Answer This is fairly easy to implement yourself: 3 If you want to handle cases where there’s more then one most frequent element, you can scan the list once to determine how many times the most frequent element(s) occur, and then scan

How can we use .class on primitive types?

When we say it prints class java.lang.Integer which makes sense because java.lang.Integer is a class. So we can have a corresponding Class object. But when I do it prints int which I felt is kind of ambiguous as .class returns an object of type Class and int is not a class (but a primitive type). What is the motive behind

How do I change the IntelliJ IDEA default JDK?

I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA

The type HashMap is not generic; it cannot be parameterized with arguments

This is a strange error i am getting today when i try to implement a Map as below. I am using JDK 1.7 and not sure why this error has been coming and changing the above line by adding cast removes the error. I looked at the related posts in stackoverflow before posting this question seems to be strange issue.

How to change a package name in Eclipse?

In Eclipse I have a simple Java project that contains a package named (default package) and inside this package I have a class. I want to rename this package into something like: com.myCompany.executable I tried to select the (default package) —> right click —> refactor but now I see only the single voice named: Infer generic type arguments but not

HQL unexpected AST node: :

My code is failing to inject the below repository. Based on the stack trace, it seems my HQL syntax is invalid, but I’m not sure what I’ve done wrong. stack trace: Update: I’m also getting this error with this query: I updated my versions to the latest: Update: I’m also getting this error with: Answer Sadly, you cannot do :order.inProduction

Advertisement