質問

here's the code DNA_seq1.insert(0,j.charAt(x)); DNA_seq2.insert(0,k.charAt(e)); DNA_align.insert(0,"|"); where DNA_seq1, DNA_seq2, and DNA_align are strings, as are j and k

and here's the error:

DNA.java:151: error: array required, but String found
                             DNA_seq1.insert(0,j[x]);
tion [x][e]take the element from the DNA sequence and ins
f the array we are building
                                                    ^
DNA.java:152: error: array required, but String found
                                 DNA_seq2.insert(0,k[e]);
                                                    ^
DNA.java:153: error: cannot find symbol
                                 DNA_align.insert(0,"|");
                                          ^
  symbol:   method insert(int,String)
  location: variable DNA_align of type String

i seriously don't understand why im getting this error. im thinking its something obvious but my mind is kind of burnt at this point, and its just not clicking.

役に立ちましたか?

解決

It's hard to tell from your post what's going on. But ...

DNA_align.insert(0,"|");

If DNA_align really is a String, then there's no insert method, as AnubianNoob pointed out. If you're trying to insert | before the first character of the string, then you can just concatenate it, like this:

"|" + DNA_align;

Also, note that strings are immutable in Java; if s is a String, there is no method s.method(whatever) that modifies the contents of s. There are some methods that make changes to the string and return the changed string as a new string, but s's contents will not be modified. So if you were hoping for a method that changed DNA_align by inserting something into it, forget it. You have to reassign DNA_align, like:

DNA_align = "|" + DNA_align;

他のヒント

String doesn't have an insert() method.

Anubian Noob is correct, there is no insert() function. If you want to do this you can do something like:

String str = "Hello ";
str = str.substring(0, 5) + "World" + str.substring(5, str.length());
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top