[Solved] Trouble with finding a substring in a string [closed]

Set<String> words = new HashSet<>(); String str = “Java Ruby PHP. Java is good. PHP please looks at Java”; Matcher mat = Pattern.compile(“\\b(\\w+)(?=\\b.*\\1)”).matcher(str); while(mat.find()){ words.add(mat.group(1)); } System.out.println(words); Also you can just split string by words and calculate count using Map. And then filter words with count > 1. 1 solved Trouble with finding a substring … Read more

[Solved] How to extend both fragment and AppCompatActivity to a same class?

I have changed your code. Problem was: findViewById(). Activity already have findViewById() method so you can call it in Activity. But Fragment don’t have this method. In Fragment you have to find a View by View.findViewById() method, here View will be the view you are inflating in onCreateView() new ViewPagerAdapter(this). To create a View you … Read more

[Solved] Write Java Program to grade Scala Homeworks

You can compile Scala into a .class file (e.g. “scalac ./foo.scala”) and run methods from your Java grading program. This might be useful reference: How do you call Scala objects from Java? solved Write Java Program to grade Scala Homeworks

[Solved] How to convert string to boolean condition in java/android?

Returning code from server is terrible awful. Anyways, this code I give you do some steps: removes new lines and multispaces into one length space from input. finds words by pattern where word starts with if and ends with digits. Adds them to array. prepares pattern with user chosen options combining into similar to (Q4a.NAOK==\”7\” … Read more

[Solved] Java snake game

You could use a Stack or LinkedList for this. Now with every move of the snakes head you add its position (x,y) to the start of the list and remove the last element if there are more elements in the list as the snake length. And while painting you first paint the background and then … Read more

[Solved] i want to make typing ‘http://’ is not necessary. how can i do?

I think this can be achieved by checking whether the string is a valid url using a regex. This regex is got from another SO post: “\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]” You first check whether url is a valid url using this regex. If the url is something like google.com, it does not match. If the url does not … Read more

[Solved] convert circle into heart 2d android [closed]

MathWorld had a great heart shaped function; http://mathworld.wolfram.com/HeartCurve.html Basically you have to do something like this in your code; float fraction = (float) this.currentStep / (float) this.steps; –> float t = this.currentStep * 2.0 * Math.PI / (float) this.steps; this.x = 16.0 * Math.pow(Math.sin(t), 3.0)); this.y = 13.0 * Math.cos(t) – 5.0 * Math.cos(2.0 * … Read more

[Solved] I need to create an array list in java i think?

public class Persons { int id;//persons id String name;//persons name String email;//persons email public Persons(int idNum, String student, String eAddress){ this.id = idNum; this.name = student; this.email = eAddress; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** * Id number * @return integer of the id */ public int getId(){ return id; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** * name of person * … Read more

[Solved] Send content body with HTTP GET Request in Java [closed]

You need to use the below public class HttpGetWithBody extends HttpEntityEnclosingRequestBase { @Override public String getMethod() { return “GET”; } } HttpGetWithBody getWithBody = new HttpGetWithBody (); getWithBody.setEntity(y(new ByteArrayEntity( “<SOMEPAYLOAD FOR A GET ???>”.toString().getBytes(“UTF8”)));); getResponse = httpclient.execute(getWithBody ); Import needed will be org.apache.http.client.methods.HttpEntityEnclosingRequestBase; solved Send content body with HTTP GET Request in Java [closed]

[Solved] Java: How to fix ArrayIndexOutOfBoundsException? [closed]

You are out of array because in for you use i<=s.length but max index of array is s.length-1 But I am interested in this String[] data = new String[(scn.nextLine()).length()]; data = (scn.nextLine()).split(“,”); Why are you creating empty array and then replace it with new one? I think you wanted to create something more like this … Read more