You can’t use array subscripts: []
, to index into a String
, and both hidden
and original
are Strings
.
You can instead use original.charAt(i)
to read a character at an index.
As for writing a character at an index: java Strings
are immutable, so you can’t change individual characters. Instead make hidden
a StringBuilder
, or simply a char[]
:
// in your class member declarations: char hidden[] = createHidden(); // possible implementation of createHidden: char[] createHidden() { if (original != null) return new char[original.length()]; else return null; }
And then your loop can use original.charAt
like so:
if (this.original.charAt(i) == input) { found = true; this.hidden[i] = this.original.charAt(i);
Related Posts:
- What does Java option -Xmx stand for? [duplicate]
- Finding white rectangle in an image
- How to use the toString method in Java?
- Unable to find valid certification path to requested target – error even after cert imported
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- Eclipse/Maven error: “No compiler is provided in this environment”
- Reverse a string in Java
- Is there any doubly linked list implementation in Java?
- What is a JavaBean exactly?
- Can’t execute jar- file: “no main manifest attribute”
- Java – What does “\n” mean? [duplicate]
- must declare a named package eclipse because this compilation unit is associated to the named module
- Exception in thread “main” java.lang.StackOverflowError
- Best way to convert an ArrayList to a string
- Rock, Paper, Scissors Game Java
- How do I reverse an int array in Java?
- Why should a Java class implement comparable?
- How Long Does it Take to Learn Java for a Complete Newbie?
- Java JDK – possible lossy conversion from double to int
- Global variables in Java
- Array ArrayList python equivalent
- Java ArrayList copy
- Lombok and Maven
- java Arrays.sort 2d array
- what is the difference between `public class` and just `class`?
- Copying and modifying array elements
- How to send Https Post request in java
- Explain the use of a bit vector for determining if all characters are unique
- What does the following Oracle error mean: invalid column index
- Sorting HashMap by values
- Will Arrays.sort() increase time complexity and space time complexity?
- How can I concatenate two arrays in Java?
- Difference between spring @Controller and @RestController annotation
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Sort a single String in Java
- Difference between slf4j-log4j12 and log4j-over-slf4j
- Java, “Variable name” cannot be resolved to a variable
- What is Java String interning?
- What condition does while(true) test? When is it true and false?
- “Unmappable character for encoding UTF-8” error
- UnsatisfiedDependencyException: Error creating bean with name
- Random shuffling of an array
- How to convert int[] to Integer[] in Java?
- Why am I getting a “; expected” error?
- How/where to download openjdk/openjre for windows [duplicate]
- copy a 2d array in java
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException
- Generating all permutations of a given string
- imageio.IIOException: Can’t read input file
- Difference between OpenJDK and Adoptium/AdoptOpenJDK
- Compile failed; see the compiler error output for details
- Java: Rotating Images
- Invalid character constant in java
- How to pass a function as a parameter in Java?
- ResultSet exception – before start of result set
- The activity must be exported or contain an intent-filter
- Cannot resolve symbol “Intent”
- What is the default initialization of an array in Java?
- java sort using anonymous class
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- channel 3: open failed: connect failed: Connection refused
- Java Currency Number format
- How do I draw a triangle?
- Java path..Error of jvm.cfg
- How to fix the compiler error in this program?
- Unreachable code in eclipse
- “Field can be converted to a local variable” message appearing when setting Android ActionBar colour
- Convert an integer to an array of digits
- Google firebase check if child exists
- How can I initialize a LinkedList with entries/values in it?
- How to resolve Unable to load authentication plugin ‘caching_sha2_password’ issue
- Deleting an object in java?
- Recompile with -Xlint:deprecation for details
- How to determine an object’s class?
- Division of integers in Java
- Consider this code: “int s = 20; int t = s++ + –s;”. What are the values of s and t?
- Reading a .txt file using Scanner class in Java
- “\b” in Java – Windows implemented
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/JDBC_DBO]]
- System.out.println function syntax in C++
- package org.json does not exist when importing org.json.JSONObject
- How to add an element at the end of an array?
- Fields in interfaces
- How to print out all the elements of a List in Java?
- How to send data to COM PORT using JAVA?
- PrintWriter failing to print to file
- Append a single character to a string or char array in java?
- for each loop in groovy
- Details of difference between @see and @inheritDoc
- add string to String array
- Difference between System.getProperty(“line.separator”); and “\n”?
- creating array without declaring the size – java
- Downloading Java JDK on Linux via wget is shown license page instead
- What is the purpose of Java DOT operator?
- Return outside method error
- How to define a relative path in java
- Java rules for casting
- No content to map due to end-of-input jackson parser