[Solved] How can I separate a single String into two parts? [duplicate]

You used to have str.split(“,”); and split() is a void method. It doesn’t alter str. you could fix it by replacing str.split(“,”) with: str = str.split(“,”), or you could put it all on one line like: while ((str = br1.readLine()) != null) userstr.add(str.split(“,”)[0]); 2 solved How can I separate a single String into two parts? … Read more

[Solved] Tried to solve the “Close Far” exercise [closed]

You basically need to compare a with both b and c (using Math.abs(a-b) and using Math.abs(a-c)) and then check if the other values differ by at least 2. Something like this: public static boolean closeFar(int a, int b, int c) { return ( (Math.abs(a-b) == 1 && (Math.abs(a-c) >= 2 && Math.abs(b-c) >= 2) || … Read more

[Solved] Implementing Comparable [closed]

Exception in thread “main” java.lang.ClassCastException: A cannot be cast to java.lang.Comparable This means the version of A you are running is not Comparable. Most likely you have two versions of A or you didn’t build the class correctly. I suggest using an IDE to build you classes and doing a clean build should fix this. … Read more

[Solved] Prevent to add data in ArrayList of type Class

There’s a pretty simple way to check if an item already exists in the list: Override the equals method. You will have to override the equals method inside your ExampleItem class. I don’t know the contents, ie. code, of your ExampleItem but this is just my guess so I suggest you to change your code … Read more

[Solved] how to use the schedule method

24 hours in a day, 60 minutes in an hour, 60 seconds in a minute, 1000 milliseconds in a second scheduleAtFixedRate(yourTask, initialDelay, 24 * 60 * 60 * 1000); solved how to use the schedule method

[Solved] How does a while loop inside a for loop work?

It will enter the for loop first when i = 0. Immediately after it will enter the while loop and continue running indefinitely as i will always be 0 and therefore < 3. You perhaps need to deal with j in the break condition of inner loop for avoiding an infinite loop. solved How does … Read more

[Solved] Get string line by line android programmatically

I think you can go for an approach like this. int clicks = 0; Button checkButton = (Button) findViewById(R.id.check_Button); checkButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EditText editBox = (EditText) findViewById(R.id.edit_Text); String items = editBox.getText().toString(); if (i == 0) { Toast.makeText(getApplicationContext(), items , Toast.LENGTH_LONG).show(); i++; editBox.setText(“”); } else if (i == 1) { Toast.makeText(getApplicationContext(), … Read more

[Solved] how to check the range using only if statement

if you want to check the difference between two numbers, you need to subtract them. The result may be negative if the first number is smaller than the second, so you may want to use Math.abs() which will make it positive again. Then you have a positive number that you can check for being between … Read more

[Solved] is there a way to have a “main” arraylist? [closed]

List<List<Citizen>> mainList= new ArrayList<>(); You can go with List of List. Also need to consider below points. I recommend using “List” instead of “ArrayList” on the left side when creating list objects. It’s better to pass around the interface “List” because then if later you need to change to using something like Vector (e.g. you … Read more