[Solved] ArrayList for handeling many Objects?

If you have constant pool of Excersises, and you only need to access them by index, then you can use array instead: Excersise[] excersises = new Excersise[EXCERSIZE_SIZE]; //fill excersises //use excersises workout.add(excersises[index]); ArrayList is designed to have fast access to element by index, and it is using array underneath, but it has range check inside … Read more

[Solved] How to send data to new Android activity

RadioGroup radioGroup = (RadioGroup) this .findViewById(R.id.radio_group); radioGroup .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int id) { final RadioButton radioButton = (RadioButton) radioGroup .findViewById(id); String selectedText = radioButton.getText().toString(); Intent i = new Intent(this, PersonData.class); i.putExtra(“cakedata”, selectedText); startActivity(i); } }); solved How to send data to new Android activity

[Solved] Write an application that inputs three integers from the user and displays the sum, average, product, smallest and largest of the numbers

import java.util.Scanner; // exercise 2.17 public class ArithmeticSmallestLargest { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num1; int num2; int num3; int sum; int average; int product; int largest; int smallest; System.out.print(“Enter First Integer: “); num1 = input.nextInt(); System.out.print(“Enter Second Integer: “); num2 = input.nextInt(); System.out.print(“Enter Third Integer: “); num3 … Read more

[Solved] Java if statements without brackets creates unexpected behaviour

Because this: if(name.equals(“email_stub”)) if(emailStub == “”) emailStub = results.getString(“text”); else if(name.equals(“fax”)) if(fax == “”) fax = results.getString(“text”); Is actually this: if(name.equals(“email_stub”)) if(emailStub == “”) emailStub = results.getString(“text”); else if(name.equals(“fax”)) if(fax == “”) fax = results.getString(“text”); Without the curly brackets, the else will reference the first if before it. And as @Hovercraft commented: Avoid if(emailStub == … Read more

[Solved] Why is the program throwing this error??: Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 36

Why is the program throwing this error??: Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 36 solved Why is the program throwing this error??: Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 36

[Solved] Substring a string from both end in java [duplicate]

You could parse XML or use regex. To keep things simple, I would suggest regex. Here is how you can use it: Pattern pattern = Pattern.compile(“<span id=\”artist\”>(.*?)<\\/span><span id=\”titl\”>(.*?)<\\/span>”); Matcher m = pattern.matcher(input); if (m.find() { MatchResult result = m.toMatchResult(); String artist = result.group(1); String title = result.group(3); } Where input is the XML you have. … Read more

[Solved] How to perform Computations in Array list?

This is the sample answer .When I checked your question,I saw that I need to create one person class with name,accountNo,amount,accType,Date.When we check two array List to subtract,we need to find same AccountNo in both array.So we need to use contains method and I override equal and hashCode.My Sample Person class is just like: package … Read more

[Solved] How to search a string of key/value pairs in Java

Use String.split: String[] kvPairs = “key1=value1;key2=value2;key3=value3”.split(“;”); This will give you an array kvPairs that contains these elements: key1=value1 key2=value2 key3=value3 Iterate over these and split them, too: for(String kvPair: kvPairs) { String[] kv = kvPair.split(“=”); String key = kv[0]; String value = kv[1]; // Now do with key whatever you want with key and value… … Read more

[Solved] How to write a toString() method that should return complex number in the form a+bi as a string? [closed]

You can override toString() to get the desired description of the instances/classes. Code: class ComplexNum { int a,b; ComplexNum(int a , int b) { this.a = a; this.b = b; } @Override public String toString() { return a + “+” + b + “i”; } public static void main(String[] args) { ComplexNum c = new … Read more

[Solved] How to make a dynamic array Fibonacci series java program? [closed]

You can combine the two examples, as such: Take the DynamicArrayOfInt class, and add the main method of the Fibonacci class. Insert a new statement at the beginning of the main method instantiating a DynamicArrayOfInt object, as such: DynamicArrayOfInt arr = new DynamicArrayOfInt(); Replace every instance of numbers[x] with arr.get(x), and instances of numbers[x] = … Read more