Question

In: Computer Science

You are given a string literal “CS3360” Describe what is Stringbuilder class, 3 member methods in...

You are given a string literal “CS3360” Describe what is Stringbuilder class, 3 member methods in Stringbuilder class and use the above literal to show output of 3 methods.

Solutions

Expert Solution


StringBuilder

It is class present in java.lang package which represents mutable sequence of characters and it provides no guarantee of synchronization

Methods

1) length()- this method returns length of sequence
2) reverse()- this method reverses the given sequence
3) deleteCharAt()- this method removes the character at speciified position in sequence
Program

class StringBuilderDemo
{
public static void main(String[] args)
{
String input="CS3360";
StringBuilder builder=new StringBuilder(input);
System.out.println("After reversing sequence "+builder.reverse());
System.out.println("Length of sequence "+builder.length());
System.out.println("After deleting character at 2nd position resultant sequence "+builder.deleteCharAt(1));
}
}

Output


Related Solutions

In the following Java class, what would the following createFromString(String string) and saveToString() methods return? /**...
In the following Java class, what would the following createFromString(String string) and saveToString() methods return? /** * This class represents a DVD player to be rented. * * @author Franklin University * @version 2.0 */ public class DVDPlayer extends AbstractItem { /** * Constructor for objects of class DVDPlayer. */ public DVDPlayer() { // No code needed } /** * Creates a DVDPlayer from a string in the format * id:desc:weeklyRate:rented * @param string The string * @return the new...
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String...
Code in Java Given the LinkedList class that is shown below Add the following methods: add(String new_word): Adds a linkedlist item at the end of the linkedlist print(): Prints all the words inside of the linkedlist length(): Returns an int with the length of items in the linkedlist remove(int index): removes item at specified index itemAt(int index): returns LinkedList item at the index in the linkedlist public class MyLinkedList { private String name; private MyLinkedList next; public MyLinkedList(String n) {...
When you create a C++ class, you are given 4 default methods. What are they and...
When you create a C++ class, you are given 4 default methods. What are they and why is it important that you remember that these exist?
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String...
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String Which of the following is a correct declaration of the member in Java? 1 public String getHeaderField(String name) 2 public String getHeaderField; 3 public String getHeaderField(String) 4 public static String getHeaderField( name) ------------------------------------------------------------------------------------------------------------------------------------- Note: all answers are case sensitive. Inside a class, the declaration of a constructor looks like the following: public JButton(String text) 1. From the constructor, you infer that the name of...
Create a class DogWalker member List <String>doggies method: void addDog(String name ) //add dog to the...
Create a class DogWalker member List <String>doggies method: void addDog(String name ) //add dog to the List method: void printDogList() //print all dogs in list /* You’ll need an index. Iterate over your list of dog names in a while loop. Use your index to “get” the dog at the current index When you ‘find’ your dog name in the list, print it out */ Method: void findDogUsingWhile(String dogName) /* You’ll need an index. Iterate over your list of dog...
java programing Q: Given the following class: public class Student { private String firstName; private String...
java programing Q: Given the following class: public class Student { private String firstName; private String lastName; private int age; private University university; public Student(String firstName, String lastName, int age, University university) { this.firstName = fisrtName; this.lastName = lastName; this.age = age; this.university = university; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public University getUniversity(){ return university; } public String toString() { return "\nFirst name:" + firstName +...
Given a string of at least 3 characters as input, if the length of the string...
Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint. -------------------------------------------------------------- public class Class1 { public static String midString(String str) {     //Enter code here } }
Consider the possibility that a faculty member wanted to survey our Research Methods class on the...
Consider the possibility that a faculty member wanted to survey our Research Methods class on the legalization of marijuana as being representative of the college student population. I want you to identify possible representative problems such as the class being criminal justice students and their opinions possibly being different than the college population as a whole. Additionally, the faculty member wants to survey random college students as being representative of the community at large in regards to raising the legal...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
You are given the following class definition (assume all methods are correctly implemented): public class Song...
You are given the following class definition (assume all methods are correctly implemented): public class Song { ... public Song(String name, String artist) { ... } public String getName() { ... } public String getArtist() { ... } public String getGenre() { ... } public int copiesSold() { ... } } Write NAMED and TYPED lambda expressions for each of the following, using appropriate functional interfaces from the java.util.function and java.util packages (Only the lambda expression with no type+name will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT