1

I have two problem. Please try to solve...

No 1. Suppose I have two string:-

String one = "Android is awesome";
String two = "Android is";

Now my question is, can I get awesome by comparing those two string like we do with int.

int abc = 50;
int def = 35;
int ghi = abc - def;

output :-

ghi = 15;

So, this is what we do basically with int, long, double... Is it possible also with String?

No 2. Now, suppose again I have a string-array

ArrayList<String> list = new Arraylist()<>;
list.add("beautiful");
list.add("awesome");
list.add("cool");

Now, if string-comparing is possible, then suppose I have got a new String three from comparing one and two.

So, here,

String three = "awesome";

Now, again, I am using if-statement

if(list.contains("awesome")){

**Problem here starts. See the commented texts**

//Here if **awesome** is found in **list**, so can I get the position of **awesome** in the **list**?
}

Forgive me for a big and rough question. Please help me. I am really so sad with this problem.

5
  • I don't understand what you are trying to achieve. But if you want to get position of certain element in list you can use indexOf method of ArrayList docs.oracle.com/javase/7/docs/api/java/util/… Commented Mar 21, 2016 at 12:11
  • i don't understand your first question. What is suppose to be the result of "Android is awesome" - "Android is" ? Awesome ? Or another thing ? For the second question, use methods contains and indexOf of Arralist Commented Mar 21, 2016 at 12:15
  • And is it possible to complete two string and get the value? Commented Mar 21, 2016 at 12:15
  • I mean, I want to compare those two string one and two and get the result into another string mamed three Commented Mar 21, 2016 at 12:18
  • yes yes. I want the result of "Android is awesome" - "Android is"... Commented Mar 21, 2016 at 12:20

1 Answer 1

1

If you want the remaining string by comparing two strings, try the following

String one = "Android is awesome";
String two = "Android is";
    if(one.contains(two)){
        Log.i("remaining string ",one.split(two)[0].replace(" ",""));
        Log.i("remaining string ",one.split(two)[1].replace(" ",""));
    }else{
        Log.i("remaining string ","");
    }

Then use the remaining string to find the index from list.Try the following ,

  list.indexOf(remainingstring);
Sign up to request clarification or add additional context in comments.

2 Comments

Glad it helps. But check for the splitted array. You may get the remaining string at 0 or 1 st position. So be careful with that.
Thanks for your care. Best of luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.