java - How search a datum in ArrayList<StringBuilder> with indexOf -
how search datum in arraylist indexof
arraylist<stringbuilder> state = new arraylist<stringbuilder>(); state.add(new stringbuilder("a")); state.add(new stringbuilder("b")); state.add(new stringbuilder("c")); state.add(new stringbuilder("d")); system.out.println(state.indexof(new stringbuilder("b"))); //out: -1
you using arraylist
of stringbuilder
objects.
as stringbuilder
used building strings, , not string
s , can't use indexof(s)
, whole object should equal 1 comparing returns true
.
in order solve problem, should build string
want stringbuilder
, , make arraylist of already-built string
s only, this:
arraylist<string> state = new arraylist<string>(); stringbuilder = new stringbuilder("a") //do whatever want state.add(a.tostring()); state.add(b.tostring()); state.add(c.tostring()); state.add(d.tostring()); ..... system.out.println(state.indexof("b")); //out: 1
Comments
Post a Comment