3.1.1.7 String-handling operations in a programming language. Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Define the purpose and syntax of the Length method.

A

Purpose: To count the characters in a String.

Syntax:
String name = “Hello”;
int j = name.length( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define the purpose and syntax of position.

A

Purpose: It is possible to determine which character features at a position within a String.
Syntax: String myStr = “Hello purple chicken”;
System.out.println(myStr.indexOf(“purple”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define the purpose and syntax of substring.

A

Purpose: The substring method extracts the characters from a String, between two specified indices, and returns the new sub string.

Syntax:

string.substring(start, end);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define the purpose and syntax of Concatenation.

A

Purpose: Used to join two or more Strings. Does not change the existing Strings, but returns a new String containing the text of the joined Strings.

Syntax:

var str1 = "Hello"; 
var str2 = "World!"; 
var res = str1.concat(str2);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define the purpose and syntax of Character → Character code.

A

Purpose: Get a specific character from a String
Syntax:

String s = "hello"; 
char c = s.charAt(0); 
//returns h
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define the purpose and syntax of character code → character.

A

Purpose: Convert a char to String.
Syntax:
character.toString( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

String to Integer.`

A

String.toInt( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

String to float.

A

String s=Float.toString(f);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define the syntax for converting Date/Time to String.

A

Date date = Calendar.getInstance().getTime();

DateFormat dateFormat = new SimpleDateFormat(“yyyy-mm-dd hh:mm:ss”);

String strDate = dateFormat.format(date);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Syntax for String to Date/Time.

A
public class 
StringToDateExample1 {

public static void main(String[] args)throws Exception {

String sDate1=”31/12/1998”;

Date date1=new SimpleDateFormat(“dd/MM/yyyy”).parse(sDate1);

System.out.println(sDate1+”\t”+date1);

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly